jquery对于checkbox一些处理
发布日期:2021-09-29 20:08:57 浏览次数:16 分类:技术文章

本文共 1465 字,大约阅读时间需要 4 分钟。

   
#判断是否选中 	$('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

转载地址:https://blog.csdn.net/horace_lee/article/details/83942972 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ruby使用技巧
下一篇:rails 3 undefined method `model_name' for ActiveRecord::Relation:Class.

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月10日 21时40分46秒