鼠标悬停在页面上的图像时生成警告框

时间:2015-12-13 06:14:51

标签: javascript jquery html5

当用户将鼠标移动到星形图像上时,我想生成一个警告框。我试图检查错误,但我找不到错误。

  <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>

3 个答案:

答案 0 :(得分: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>

Working Example

  

注意:此代码可以使用..但请搜索如何包含   jquery或如何安装jquery因为有不同的方法可以做   该

答案 1 :(得分:0)

由于你不需要鼠标输入和鼠标输出(这就是悬停的真正原因),你可能想要使用.mouseover()代替。

答案 2 :(得分:0)

您可以使用此方法:

<div onmousemove="alert('hello')">
    <p>onmousemove: <br> <span id="demo">Your Text</span></p>
</div>