在我的页面上,当鼠标悬停时,它会添加检查的属性,检查输入类型的收音机如何在鼠标内添加鼠标移除属性?如何在mouseout时删除attr?
$('span').mouseover(function(){
jQuery(this).find('input').attr('checked','checked')
});
在我的页面上,当鼠标悬停时,它会添加检查的属性,检查输入类型的收音机如何在鼠标内添加鼠标移除属性?如何在mouseout时删除attr?
$('span').mouseover(function(){
jQuery(this).find('input').attr('checked','checked')
});
可以使用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>
而不是使用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);
});
使用removeAtrr('checked')
为删除属性checked
当mouseout。
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')
});
'$( '跨度')鼠标移开(函数(){ jQuery的(本).find( '输入')removeAttr( '检查'') 。})。 ' – Ninjaneer
你所有的答案都能正常工作,但是当鼠标悬停时,它不会被检查,我用道具,而它的工作很抱歉,家伙可能是我不知道如何找出它并要求属性。我的坏 –
我认为你需要鼠标在鼠标外面。鼠标悬停attr检查并触发鼠标输出功能,因此它再次无缝检查 – JYoThI