IE,firefox下jquery擷取一組checkbox選中值的問題

來源:互聯網
上載者:User

 

HTML 代碼:
<form>
<input type="checkbox" name="newsletter" checked="checked" value="Daily" />
<input type="checkbox" name="newsletter" value="Weekly" />
<input type="checkbox" name="newsletter" checked="checked" value="Monthly" />
</form>
jQuery 代碼:
$("input:checked")
結果:
[ <input type="checkbox" name="newsletter" checked="checked" value="Daily" />, <input type="checkbox" name="newsletter" checked="checked" value="Monthly" /> ]
var check = $("input:checked"); //得到所有被選中的checkbox
   var actor_config;              //定義變數
   check.each(function(i){         //迴圈拼裝被選中項的值
    actor_config = actor+','+$(this).val();
    });
   alert(actor_config.substr(9)+',');
通過以下js代碼去擷取選中項的值,在IE7中可以正確取得選中項的值,但在IE8中卻得不到選中項的值,同樣在Firefox 3.5.3下也得不到值,但公司同事在Firefox其他較低版本下能正確得到值,IE6下也沒有問題,⊙﹏⊙b汗
$('#permissionList-body input[name="checkboxes"][checked]').each(function(i){
 alert($(this).val());
});
      但是把技術代碼修改為:
$('#permissionList-body input[name="checkboxes"]').each(function(i){
 if(this.checked)alert($(this).val());
});
===========================================================================
$('#permissionList-body input[name="checkboxes"][checked]')
$('#permissionList-body input[name="checkboxes"][checked='checked']')
這兩種寫法支援IE
$('#permissionList-body input[name="checkboxes"][checked='true']')

這種支援firefox

沒有找到好的解決方案,只有加if(this.checked)判斷了

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.