我有这个代码,它不能工作。
.on("click","span.name", function selectThisName(e) {
if (e.altKey) {
username = jQ(this).text();
if (username != 'None') {
jQ("span.name:contains('" + username + "')").closest('.namedesign').prev().prev().attr('checked', 'checked');
e.preventDefault();
updateCheckedCount();
}
}
}它以前是有效的,但现在不行了。如果我按下相同的三个或四个垃圾邮件发送者的名字,它应该会更快地检查发帖字段旁边的所有框。
然而,我也有这段代码,它神奇地工作。它侧重于唯一的用户标识;元素本身包括标识,而不像用户名是“基于文本的”。这是该网站的代码:http://puu.sh/9wxbw/03cb74487e.png
.on("click","span.ident", function selectThisID(e) {
if (e.altKey) {
identification= "id_" + jQ(this).text();
jQ("span." + identification).closest('.namedesign').prev().prev().attr('checked', 'checked');
e.preventDefault();
updateCheckedCount();
}
})在这种情况下,我想altclick的名字“心碎”来检查他们的所有帐户帖子,但它不起作用。但是,如果我在ID上按Alt键,它就可以工作。
为什么我需要这个?嗯,有时候我不得不选择名字而不是身份。ID是基于IP的(它们总是变化的,否则人们不会发送垃圾邮件),而名称不是,许多用户帐户已经被劫持。
发布于 2014-06-17 04:50:45
使用.prop('checked', true)代替.attr('checked', 'cheked')
$().prop() documentation.
示例:JS Bin
编辑:
您可以在没有jQuery的情况下设置checked属性:
$('input:checkbox').each(function(){
//Get your input of type checkbox and set his property `checked` to boolean value:
//Note: this is <input type='checkbox'>
var isChecked = this.checked;
this.checked = !isChecked;
//Or using jQuery variable:
$(this)[0].checked = true;
});https://stackoverflow.com/questions/24251940
复制相似问题