Events 单选按钮在悬停事件中看起来已选中?
是否可以通过鼠标悬停事件来控制单选按钮的显示Events 单选按钮在悬停事件中看起来已选中?,events,radiobuttonlist,Events,Radiobuttonlist,是否可以通过鼠标悬停事件来控制单选按钮的显示 目标是,当鼠标结束时,它看起来是选中的,当鼠标离开时,它看起来是未选中的。但它只有在单击时才会被检查,就像评级一样。您可以使用以下内容: $("input:radio").hover(function(){ $(this).prop('checked', true); }, function(){ //MouseOut event $(this).prop('checked', false); }).c
目标是,当鼠标结束时,它看起来是选中的,当鼠标离开时,它看起来是未选中的。但它只有在单击时才会被检查,就像评级一样。您可以使用以下内容:
$("input:radio").hover(function(){
$(this).prop('checked', true);
}, function(){
//MouseOut event
$(this).prop('checked', false);
}).click(function(){
//Unbind the hover event for all the radio buttons
$("input:radio").unbind('mouseenter mouseleave')
//Check clicked radio button
$(this).prop('checked', true);
});
我为你做了一把小提琴:在摆弄了一点之后,我想出了这个…看看这个,看看是否有什么诀窍…哦,因为你没有提到任何特定的语言,所以我用jQuery实现了这个功能…希望它能有所帮助 这可能不是一个完美的解决方案,但它肯定满足以下要求: HTML:
你试过什么吗?如果是,请分享,这样我们可以帮助你。。。
<input type="radio" name="cols" id="col-1" />
<br />
<input type="radio" name="cols" id="col-2" />
<br />
<input type="radio" name="cols" id="col-3" />
var clicked = false;
var clickedId;
$('input').click(function () {
clicked = true;
clickedId = $(this).attr('id');
});
$('input').hover(function () {
$(this).prop('checked', true);
}, function () {
if (clicked === true) {
$('#' + clickedId).prop('checked', true);
} else {
$(this).prop('checked', false);
}
});