admin管理员组文章数量:1426790
I need to get the value of the first checkbox which is checked and who's class name begins with 'rqc', eg. rqc205
I have tried this: requestID=$('#requestsTable').find('input[class^='rqc']:checked').val();
but it yields nothing, whereas requestID=$('#requestsTable').find('input:checked').val();
works but does not limit to the class.
I need to get the value of the first checkbox which is checked and who's class name begins with 'rqc', eg. rqc205
I have tried this: requestID=$('#requestsTable').find('input[class^='rqc']:checked').val();
but it yields nothing, whereas requestID=$('#requestsTable').find('input:checked').val();
works but does not limit to the class.
2 Answers
Reset to default 5You have a syntax error. Either fix your quotes around the attribute value, or remove them altogether (they don't seem to be required).
requestID = $('#requestsTable').find("input[class^='rqc']:checked").val();
or
requestID = $('#requestsTable').find("input[class^=rqc]:checked").val();
Perhaps:
requestID = $('#requestsTable').find('input[class^="rqc"]').filter(':checked').val();
This is, currently un-checked/un-verified. I think it should work, but I'm still new to jQuery, so I'll post the possibility, check it and then amend if necessary.
Much to my surprise, that works.
But it's worth pointing out, I think, that it might be easier to get the value using jQuery's click()
event.
$(document).ready(
function() {
$('input[class^="rqc"]').click(
function() {
var requestID = $(this).val();
}
);
}
);
Though obviously that depends on what exactly you're doing, and why.
本文标签: javascriptjQuery Selectorchecked and class begins withStack Overflow
版权声明:本文标题:javascript - jQuery Selector - checked and class begins with - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745479074a2660096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论