我的问题是,我想在运行时检索复选框 id 并稍后将它们用于其他目的。但是检索到的 id 被读取为对象。
我的代码是:
// Following code gives id of checkbox which contains myCheckbox as its id.
var myCheckbox= $('input[id$=myCheckbox]')[0].id;
// and Now I want to check if that checkbox is checked with following code:
if ($(myCheckbox).is(':checked'))
return 1;
else
return 0;
但是这里 myCheckbox id 被读取为 Object 而不是 id ,因此总是在 else 条件下输入并返回 0。当我直接输入复选框的 id 时,此代码有效。
if ($('#ctl001_myCheckbox').is(':checked'))
return 1;
else
return 0;
它不应该那么复杂,我一直在使用 Javascript,但对 JQuery 来说是新手。