setAttribute(“选中",“选中")仅工作一次 [英] setAttribute("checked", "checked") only works one time
本文介绍了setAttribute(“选中",“选中")仅工作一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正面临一个问题
HTML
<input id="cb" type="checkbox" name="Employment_Staus" value="E" />
<input type="button" value="Check" id="id" />
JQUERY
$('#id').click(function(){
$('input[type="checkbox"]')[0].setAttribute("checked", "checked");
});
第一次单击check button
时,它会起作用!(选中复选框),然后我手动取消选中该复选框!
First time when I click on check button
, it works!(it check the check-box ), then I manually uncheck the check box!
当我在手动取消选中后再次按check button
时,它不起作用!
When I press check button
again after uncheck manually , it not work!
我不想使用attr或prop等等等!
I don't want to use attr or prop etc etc !!
示例
http://jsfiddle.net/wL6qr0hp/4/
推荐答案
checked
属性设置默认状态,而不是当前状态>状态.
The checked
attribute sets the default state, not the current state.
改为修改checked
属性(使用.checked = true
).
这篇关于setAttribute(“选中",“选中")仅工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文