开发者

Jquery to find which checkbox is checked?

I have 10 chec开发者_开发知识库kboxes in my page, dynamically created by jquery.

Its starts like chk1 , chk2 and....so on.

I want to get which checkbox is checked out of 10 checkboxes .

for (i=0; i < tbl01.length; i++)
{
if ($("input[type=checkbox][checked]"))
{
var checked = chk+i;

}
}

where

tbl01

is my dataset to dynamically create my checkboxes

I have tried to some extent, is this correct ?


Use the :checked selector:

$("input[type=checkbox]:checked")

Also, if you're just checking whether an element exists, you'll want to check .length on the returned selector (because jquery always returns an object, it just might not have anything in it):

if ($("input[type=checkbox]:checked").length) {
  // do stuff
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜