jquery对于checkbox一些处理

<input type="checkbox" name="foo" value="bar" />
<input type="button" onclick="show_checked()" value="Show" />
<input type="button" onclick="set_checked(true)" value="On" />
<input type="button" onclick="set_checked(false)" value="Off" />



#判断是否选中
$('input[name=foo]').is(':checked')
$('input[name=foo]').attr('checked')


#选中和不选中
$('input[name=foo]').attr('checked', true);
$('input[name=foo]').attr('checked', false);



判断是否选中,开始用的办法



$(function() {
$('#isOther').click(function() {
var other = $('#isOther:checked').val();
if (other != undefined) $('#other').removeAttr('readonly');
else $('#other').attr('readonly', 'readonly');
});
});



其实可以

var checked = $('input[type=checkbox]').attr('checked');


返回一个jason对象,是有结构的

var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};

myData = JSON.parse(text, function (key, value) {
var type;
if (value && typeof value === 'object') {
type = value.type;
if (typeof type === 'string' && typeof window[type] === 'function') {
return new (window[type])(value);
}
}
return value;
});



一些参考:
都是把一组复选框是否选中情况,得到。等着ajax发出去

var sList = "";
$('input[type=checkbox]').each(function () {
var sThisVal = (this.checked ? "1" : "0");
sList += (sList=="" ? sThisVal : "," + sThisVal);
});
console.log (sList);

另一个

var str = "";

$(':checkbox').each(function() {
str += this.checked ? "1," : "0,";
});

str = str.substr(0, str.length - 1); //Remove the trailing comma
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值