在我的页面上,当鼠标超过它时,会添加属性的选中,检查输入类型,收音机,如何在鼠标内部添加鼠标,删除属性?
$('span').mouseover(function(){
jQuery(this).find('input').attr('checked','checked')
});发布于 2017-04-12 05:56:59
您可以使用event在单个函数中检查这一点。
$(document).on('mouseenter mouseleave', 'span', function(evt) {
evt.type === 'mouseenter' ? $(this).find('input').prop('checked', true) : $(this).find('input').prop('checked', false);
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>
<input type="checkbox" id="chk" >
</span>
发布于 2017-04-12 05:35:55
与其使用attr('checked','checked'),不如使用以下代码:
.attr('checked',true); // to make checked
.attr('checked',false); // to make uncheck在您的示例中,要使它在mouseout上不受检查,请尝试如下:
$('span').mouseout(function(){
jQuery(this).find('input').attr('checked',false);
});发布于 2017-04-12 05:48:27
当鼠标退出时,使用removeAtrr('checked')删除属性checked。
HTML代码-
<span>
<input type="checkbox" id="chk1" >
</span>
<span>
<input type="checkbox" id="chk2" checked >
</span>JAVASCRIPT代码-
$('span').mouseout(function(){
jQuery(this).find('input').removeAttr('checked');
});
$('span').mouseover(function(){
jQuery(this).find('input').attr('checked','checked')
});https://stackoverflow.com/questions/43361046
复制相似问题