天天看点

java 单选框 取消选中,radio(单选框)反复选中与取消选中

java 单选框 取消选中,radio(单选框)反复选中与取消选中

做个记录,以便需要拿取

$(function(){

第一种

$('input:radio').click(function(){

//alert(this.checked);

//

var domName = $(this).attr('name');

var $radio = $(this);

// if this was previously checked

if ($radio.data('waschecked') == true){

$radio.prop('checked', false);

$("input:radio[name='" + domName + "']").data('waschecked',false);

//$radio.data('waschecked', false);

} else {

$radio.prop('checked', true);

$("input:radio[name='" + domName + "']").data('waschecked',false);

$radio.data('waschecked', true);

}

});

第二种

var old = null; //用来保存原来的对象

$("input[name='sex']").each(function(){//循环绑定事件

if(this.checked){

old = this; //如果当前对象选中,保存该对象

}

this.onclick = function(){

if(this == old){//如果点击的对象原来是选中的,取消选中

this.checked = false;

old = null;

} else{

old = this;

}

}

});

});

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:[email protected]

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有