CheckBox 選中取值以及回填


html:

                    <td align="left" style="word-wrap:break-word;word-break:break-all;" colspan="3">
                        <input name="ck" type="checkbox" value="1"/><span>按計划進行</span> 
                        <input name="ck" type="checkbox" value="2"/><span>進度順利但有延誤風險</span> 
                        <input name="ck" type="checkbox" value="3"/><span>延誤</span> 
                    </td>

獲取選中值:

1、CheckBox為單選:

$("input:checkbox:checked").val()
或者
$("input:[type='checkbox']:checked").val();
或者
$("input:[name='ck']:checked").val();

2、CheckBox為多選:

$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val());
}
});

3、全選:

$('input:checkbox').each(function() {
$(this).attr('checked', true);
});

4、全不選:

$('input:checkbox').each(function () {
$(this).attr('checked',false);
});

5、CheckBox回填:

$('input:checkbox:first').attr("checked",'checked');
或者
$('input:checkbox').eq(‘+索引變量+’).attr("checked",'true');
或者
$('input:checkbox[value='+CheckBox值+']').attr('checked','true');
多個回填:
$('input:radio').slice(0,2).attr('checked','true');

6、CheckBox只能單選

$(":checkbox").click(function(){
  if($(this).is(':checked')){
    $(this).attr('checked',true).siblings().attr('checked',false);
  }
});

 





 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM