- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个 jQuery 代码可以处理悬停在评级星星上的问题,当您将鼠标悬停在星星上时,它们会按照预期的方式发光。问题是,一旦您将光标移开,它仍会显示光标所在的位置(并且不显示原始评分)。我如何让它检查光标何时被移除,然后显示原始评分?
$(document).ready(function() {
$("[id^=rating_]").hover(function() {
rid = $(this).attr("id").split("_")[1];
$("#rating_"+rid).children("[class^=star_]").children('img').hover(function() {
$("#rating_"+rid).children("[class^=star_]").children('img').removeClass("hover");
/* The hovered item number */
var hovered = $(this).parent().attr("class").split("_")[1];
while(hovered > 0) {
$("#rating_"+rid).children(".star_"+hovered).children('img').addClass("hover");
hovered--;
}
});
});
$("[id^=rating_]").children("[class^=star_]").click(function() {
var current_star = $(this).attr("class").split("_")[1];
var rid = $(this).parent().attr("id").split("_")[1];
$('#rating_'+rid).load('http://localhost:8888/fivestars/send.php', {rating: current_star, id: rid});
});
});
编辑:为具有 3 星评级的内容输出 HTML:
<div id="rating_3">
<span class="star_1"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" class="hover" /></span>
<span class="star_2"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" class="hover" /></span>
<span class="star_3"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" class="hover" /></span>
<span class="star_4"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" /></span>
<span class="star_5"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" /></span>
</div>
最佳答案
更新:
所选评分存储在 ratings_x 元素的 data()
中,并在您离开评分区域时检索。
$('[class^=star_]').mouseenter(
function() {
if($(this).parent().data('selected') == undefined) {
var selectedStar = $(this).parent().find('.hover').length - 1;
$(this).parent().data('selected', selectedStar)
}
$(this).children().addClass('hover');
$(this).prevAll().children().addClass('hover');
$(this).nextAll().children().removeClass('hover');
});
$('[id^=rating_]').mouseleave(
function() {
var selectedIndex = $(this).data('selected')
var $selected = $(this).find('img').eq(selectedIndex).addClass('hover').parent();
$selected.prevAll().children().addClass('hover');
$selected.nextAll().children().removeClass('hover');
});
hover()
的正确用法是有两个函数:
$('#myElement').hover(
function() {
// mouseenter code
},
function() {
// mouseleave code
}
);
使用第二个函数设置鼠标离开元素时的正确 View 。
关于javascript - jQuery Javascript 评级 : Making the rating reappear when user takes their cursor off,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2351903/
所以我正在尝试遵循冲压喷气发动机的代码 http://www.rich-harris.co.uk/ramjet/ ,但我无法让元素 a 在移动到 b 时消失。我还得到 --Uncaught TypeE
一个最近部署的功能齐全的Azure功能应用被删除,报告不存在,但几分钟后它又出现在资源组中。是什么导致了它的复活,如何避免它?。以下是详细信息。。自动化集成测试有3个步骤。。在最后的删除步骤中,脚本首
window XP SP3; TortoiseSVN 1.6.16,Build 21511 - 32 Bit,目前是当前版本。 我们正在使用 Eclipse Helios 进行一些 Android 开
我正在设置一个登录 Activity ,其中包含用户名和密码。我想在应用程序尝试让用户登录系统时禁用用户名和密码编辑文本字段。 signInButton.setOnClickListener(
我有这个 jQuery 代码可以处理悬停在评级星星上的问题,当您将鼠标悬停在星星上时,它们会按照预期的方式发光。问题是,一旦您将光标移开,它仍会显示光标所在的位置(并且不显示原始评分)。我如何让它检查
环境:VS2008,C++ ATL COM,64Bit,Windows 7 我正在尝试从较旧的 COM 接口(interface)中删除一个方法。我修改了 *.idl,修改了相关的 *.h 和 *.c
我有一个在 Mac OS X 上运行的 SWT 应用程序。当用户单击 shell 的“关闭”按钮时,我忽略关闭请求并通过调用 Shell.setVisible(false) 隐藏 shell。 现在,
我是一名优秀的程序员,十分优秀!