开发者

checkbox status [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form.开发者_Go百科 For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜