動態產生的checkbox 若要做判斷是否有被勾選到

最基本的方法就是

  for( int i = 0; i < checkboxlist.length; i++ )
    {
       if( checkboxlist[ i ].checked )
       {
          // do other stuff
       }
    }

但若是只有動態產生一個的話,會出現錯,因此必須要做修正,否則會一直出錯

Get checkboxlist in javascript and check the status of the checkboxes

http://forums.asp.net/p/985229/1270140.aspx

var chk=document.getElementById( form);   // form is the form name in your page
var checkboxlist = chk.CheckBoxListName;

if( checkboxlist.length == undefined )    
{
       // in this case you have a single element on page - not an array
       if( checkboxlist.checked )
       {
             // do something
       }
}
else
{
    // we do have more than one element
    for( int i = 0; i < checkboxlist.length; i++ )
    {
       if( checkboxlist[ i ].checked )
       {
          // do other stuff
       }
    }
}

arrow
arrow
    全站熱搜

    包爾伯 發表在 痞客邦 留言(0) 人氣()