現在、このコードを使用してチェックボックスをカスタム コントロールとして表示していますが、完璧に動作します。
// Create the checkbox and add it to the DOM.
var checkbox = $("<input type='checkbox'/>")
.css({
height: 20,
width: 20,
margin: "10px"
})
.appendTo($(element));
// Determine if the change was initiated by the user.
var changingValue = false;
checkbox.change(function () {
changingValue = true;
contentItem.value = checkbox[0].checked;
changingValue = false;
});
contentItem.dataBind("value", function (newValue) {
if (!changingValue) {
checkbox[0].checked = newValue;
}
});
ただし、これを少し拡張したいと思います。真か偽かに基づいて値をカウントする方法を誰かが知っているかどうか疑問に思っています。
探しているもの: 下に 2 つのチェックボックスがあります。1つ目は「TRUE」、2つ目は「FALSE」です。
- var count などを使用してこれらの値をカウントアップし、それを while ループまたは配列に入れて、テスト目的で次のようなボタンに表示できるようにしたいと考えています。
window.alert("add in text here" + add_code_here)
したがって、データの例は次のようになります。
var trueCount = 0;
var falseCount = 0;
window.alert("There are: " + trueCount + " values that are true and " + falseCount + " that are false");
上記の例trueCount = 1
とfalseCount = 1
人々が私に与えることができる情報に感謝します。それは最も感謝しています