javascript – jquery selector / checked属性在IE7中不更新
作者:互联网
我有一个由链接调用的函数,它应该检查特定div中存在的各种复选框(传递给函数.)适用于除IE之外的所有浏览器(7.)据我所知.attr(‘checked’, ‘checked’是使用jquery 1.5.1执行此操作的正确方法
function selectall(industry){
$("#"+industry+"Apps :checkbox").attr('checked', 'checked');
$("#"+industry+"Apps :checkbox").change(); /* used for jqtransform plugin */
}
有没有我缺少的东西或更好的方法来做到这一点适用于所有浏览器?我真的不在乎取消选择,只是选择.
HTML看起来像
<div id = 'HealthcareApps'>
<div style="clear: both;">
<a href = "javascript:selectall('Healthcare');">Select all</a>
</div>
<ul>
<li><label for="id_Healthcare_0"><input type="checkbox" name="Healthcare" value="1" id="id_Healthcare_0" /> Simple Messaging</label></li>
<li><label for="id_Healthcare_1"><input type="checkbox" name="Healthcare" value="2" id="id_Healthcare_1" /> Mobile Alerts and Alarms</label></li>
<li><label for="id_Healthcare_2"><input type="checkbox" name="Healthcare" value="3" id="id_Healthcare_2" /> Patient Identification / Drug Conflicts</label></li>
</ul>
(是的,我知道内联样式是一个可怕的想法.如果我能在IE中使用此链接,我也会解决这个问题.)
解决方法:
你可以尝试这样的事:js fiddle demo
<div id = 'HealthcareApps'>
<div style="clear: both;">
<a href="#" id="selectall" class="Healthcare" >Select all</a>
</div>
<ul>
<li><label for="id_Healthcare_0"><input type="checkbox" name="Healthcare" value="1" id="id_Healthcare_0" /> Simple Messaging</label></li>
<li><label for="id_Healthcare_1"><input type="checkbox" name="Healthcare" value="2" id="id_Healthcare_1" /> Mobile Alerts and Alarms</label></li>
<li><label for="id_Healthcare_2"><input type="checkbox" name="Healthcare" value="3" id="id_Healthcare_2" /> Patient Identification / Drug Conflicts</label></li>
</ul>
</div>
jQuery的:
$('#selectall').click(function(e) {
e.preventDefault();
var industry = $(this).attr("class");
$("#" + industry + "Apps :checkbox").attr('checked', 'checked');
});
并且,要打开和关闭:
$('#selectall').click(function(e) {
e.preventDefault();
var industry = $(this).attr("class");
var checkbox = $("#" + industry + "Apps :checkbox");
checkbox.attr('checked', !checkbox.attr('checked'));
});
标签:jquery,javascript,internet-explorer-7 来源: https://codeday.me/bug/20190710/1418627.html