我正在做一个简单的 jQuery 悬停事件,但发生的情况是它仅在第一次执行。我怎样才能让它每次都执行?我的要求是每当我将光标移到 <p>
上时元素或单击其中的内容,它应该以文本形式提醒内容。
<script>
$(document).ready(function () {
$("p").hover(function () {
var s = $(this).text();
alert(s);
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
</body>
正如 ritesh 指出的,当我为 webgrid 做的时候,它并不总是给出第一个单元格文本,这是我的代码
网络网格
$(document).ready(function(){
$("#gridContent tr td:first-child").hover(function(){
var selectedEmpCode = $(this).text();
getDepartmentTable(selectedEmpCode);
},function(){
var selectedEmpCode = $(this).text();
getDepartmentTable(selectedEmpCode);
});
});
我没有得到 $(this).text()
最佳答案
HTML 代码
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").hover(function(){
$("p").css("background-color", "yellow");
alert($("p").text());
},function(){
$("p").css("background-color", "pink");
});
});
</script>
</head>
<body>
<p>Hover the mouse pointer over this paragraph.</p>
<p>If you click on me, I will disappear.</p>
</body>
</html>
关于javascript - 如何制作悬停事件,在jquery中每次都执行而不是第一次,甚至单击内容每次都执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30060977/