Javascript 将鼠标悬停在页面上的图像上时生成警报框
我想在用户在星图上移动鼠标时生成一个警告框。我试图检查错误,但找不到错误Javascript 将鼠标悬停在页面上的图像上时生成警报框,javascript,jquery,html,Javascript,Jquery,Html,我想在用户在星图上移动鼠标时生成一个警告框。我试图检查错误,但找不到错误 <html> <head> <title>Testing</title> <link rel="stylesheet" type="text/css" href="rating_style.css"/> <script type="text/javascript" src="jquery-2.1.4.min.j
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="rating_style.css"/>
<script type="text/javascript" src="jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#1_star").hover(function() {
alert("hello");
});
});
</script>
</head>
<body>
<center>
<div class="rating-container">
<div class="rating-star">
<img src="sta.png" width="50" id="1_star" />
<img src="sta.png" width="50" id="2_star" />
<img src="sta.png" width="50" id="3_star" />
<img src="sta.png" width="50" id="4_star" />
<img src="sta.png" width="50" id="5_star" />
</div>
</div>
</center>
</body>
</html>
测试
$(文档).ready(函数(){
$(“#1#星”)。悬停(函数(){
警惕(“你好”);
});
});
您应该包括jquery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#1_star").hover(function() {
alert("hello");
});
});
</script>
$(文档).ready(函数(){
$(“#1#星”)。悬停(函数(){
警惕(“你好”);
});
});
注意:此代码将起作用。。但请搜索如何包括
jquery或如何安装jquery,因为有不同的方法
那
由于您不需要同时使用鼠标输入和鼠标输出(这就是悬停的真正用途),因此您可能需要使用.mouseover()。您可以使用以下方法:
<div onmousemove="alert('hello')">
<p>onmousemove: <br> <span id="demo">Your Text</span></p>
</div>
onmousemove:
您的文本