Javascript jQuery将类设置为内部div
我试图设置一个类的收音机检查到一个div和所有以前的div在鼠标上方和删除鼠标出。问题是它将每个div的周围设置为“a”标记 有没有办法设置为内部divJavascript jQuery将类设置为内部div,javascript,jquery,Javascript,Jquery,我试图设置一个类的收音机检查到一个div和所有以前的div在鼠标上方和删除鼠标出。问题是它将每个div的周围设置为“a”标记 有没有办法设置为内部div $(function() { $('.radio-fx').live( "mouseenter", function() { // Handles the mouseover var $self = $(this); $self.addClass('radio-checked').pre
$(function() {
$('.radio-fx').live( "mouseenter", function() { // Handles the mouseover
var $self = $(this);
$self.addClass('radio-checked').prevAll().addClass('radio-checked');
$self.nextAll().removeClass('radio-checked');
}).live ( "mouseout", function() { // Handles the mouseout
$(this).removeClass('radio').prevAll().removeClass('radio');
});
});
<div class="voteGroup">
<input type="radio" id="price_0" value="1" name="price" style="display: none;" class="radio-checked">
<a href="#" class="radio-fx price radio-checked" title=" check me ">
<div class="radio"></div>
</a>
<input type="radio" id="price_1" value="2" name="price" style="display: none;" class="radio-checked">
<a href="#" class="radio-fx price radio-checked" title=" check me ">
<div class="radio"></div></a>
<input type="radio" id="price_2" value="3" name="price" style="display: none;" class="radio-checked">
<a href="#" class="radio-fx price radio-checked" title=" check me ">
<div class="radio"></div>
</a>
<input type="radio" id="price_3" value="4" name="price" style="display: none;" class="radio-checked">
<a href="#" class="radio-fx price radio-checked" title=" check me ">
<div class="radio"></div>
</a>
<input type="radio" id="price_4" value="5" name="price" style="display: none;" class="radio-checked" checked="checked">
<a href="#" class="radio-fx price radio-checked" title=" check me ">
<div class="radio-checked"></div>
</a>
</div>
$(函数(){
$('.radio fx').live(“mouseenter”,function(){//处理鼠标悬停
var$self=$(本);
$self.addClass('radio-checked').prevAll().addClass('radio-checked');
$self.nextAll().removeClass('radio-checked');
}).live(“mouseout”,function(){//处理mouseout
$(this.removeClass('radio').prevAll().removeClass('radio');
});
});
试试这个:
$self.prevAll().andSelf().children('div').addClass('radio-checked');
它查找前面元素的子元素
其他行应为:
$self.nextAll().children('div').removeClass('radio-checked');
$(this).prevAll().andSelf().children('div').removeClass('radio');
试试这个:
$self.prevAll().andSelf().children('div').addClass('radio-checked');
它查找前面元素的子元素
其他行应为:
$self.nextAll().children('div').removeClass('radio-checked');
$(this).prevAll().andSelf().children('div').removeClass('radio');
顺便说一句,live
-改用on
更新以下是在上使用的版本:
$(function() {
$('.radio-fx').on("mouseenter", function() { // Handles the mouseover
var $self = $(this);
$self.prevAll().andSelf().find('div').addClass('radio-checked');
$self.nextAll().find('div').removeClass('radio-checked');
}).on("mouseout", function() { // Handles the mouseout
$(this).prevAll().andSelf().find('div').removeClass('radio-checked');
});
});
jsFiddle
顺便说一句,live
-改用on
更新以下是在
上使用的版本:
$(function() {
$('.radio-fx').on("mouseenter", function() { // Handles the mouseover
var $self = $(this);
$self.prevAll().andSelf().find('div').addClass('radio-checked');
$self.nextAll().find('div').removeClass('radio-checked');
}).on("mouseout", function() { // Handles the mouseout
$(this).prevAll().andSelf().find('div').removeClass('radio-checked');
});
});
jshiddle.你能给我们提供一个工作示例吗?你能给我们提供一个工作示例吗?谢谢你的回答,当我悬停在上一个div上时,现在已经应用了这个类,但是当前的on-I-on没有什么好处。我已经把它分成了两个应该有效的语句。我在一行中找到了如何做到这一点:)非常感谢这一点,你知道如果不点击鼠标,我会如何将它重置回课堂广播吗?谢谢你的回复,当我悬停在前一个div上时,现在已经应用了这个类,但是当前的on I am on没有什么好处。我把它分成了两个应该可以工作的语句。我在一行中找到了如何做:)太好了,谢谢你的工作,你知道如果不点击鼠标,我会如何将它重置回课堂广播吗?是的,将切换到.on(),有一些问题,但将在itI上花费更多时间我更改了此行,现在当我将当前行悬停在突出显示的$self.children('div').addClass('radio-checked').prevAll().addClass('radio-checked');请查看更新。还添加了on
的版本和正在使用的JSFIDLE sample.yeah将改为.on(),有一些问题,但将在itI上花费更多时间。我更改了此行,现在当我悬停当前一行时,突出显示$self.children('div').addClass('radio-checked').prevAll().addClass('radio-checked');请查看更新。还添加了在
上带有的版本和正在使用的JSFIDLE示例。