checkbox status [closed]
function saveData()
{
var rows = $('#deviceTable tr').length;
var toSave = "";
alert(rows);
for(var i = 0; i < rows; i ++)
{
alert('inside for loop');
if($("#saveDevName_"+(i)).attr('checked'))
{
alert('sving the data');
toSave+=$("#devName_"+(i)).text()+",";
}
}
}
($("#saveDevName_"+(i+1)).attr('checked'))
--- is not executed.Hence not checking the status.If statement is not executed {if($("#saveDevName_"+(i)).attr('checked'))}
Plz suggest me the right approch.
Replace:
if($("#saveDevName_"+(i)).attr('checked'))
With:
if($("#saveDevName_"+(i)).is(':checked'))
More Info:
- http://api.jquery.com/checked-selector/
If you're using jQuery 1.6 then you need to either use is(":checked")
as suggested by Sarf or use prop
instead of attr
. As of 1.6 attr("checked")
is going to return the attribute value which was set when the page loaded.
http://api.jquery.com/prop/
Prior to 1.6 I believe using attr("checked")
would have worked as you expected.
精彩评论