$("#check1")
以下のステートメントで2回目の使用を回避する方法はありますか?
$("#check1").prop("checked",!$("#check1").prop("checked"));
どんなトリックでも私は以下のようなことをすることができますか?
$("#check1").prop("checked",!this.prop("checked"));
$("#check1")
以下のステートメントで2回目の使用を回避する方法はありますか?
$("#check1").prop("checked",!$("#check1").prop("checked"));
どんなトリックでも私は以下のようなことをすることができますか?
$("#check1").prop("checked",!this.prop("checked"));
関数をコールバックとして渡すと、現在の値が取得されます。
$("#check1").prop("checked", function(i, value) {
return !value;
});
.prop( propertyName, function(index, oldPropertyValue) )
propertyNameThe name of the property to set.
function(index, oldPropertyValue) A function returning the value to set. Receives the index position of the element in the set and the old property value as arguments. Within the function, the keyword this refers to the current element.
var el = $("#check1");
el.prop("checked",!el.prop("checked"));
var $check = $("#check1");
$check.prop( "checked", !$check.prop("checked") );
あなたはこれを使うことができますが、この方法で:
$("#check1").prop("checked",!$(this).prop("checked"));