Script does not work when on <head>

后端 未结 3 1130
一向
一向 2020-12-11 09:37

I proved script. its works, but outside of . I am not good on script. maybe its a simple problem.




        
3条回答
  •  臣服心动
    2020-12-11 09:42

    I think your code doesn't work because you're not running it when document's ready:

    $(document).ready(function(){
    
      $('#img1').mouseover(function () {
      $('#p1').show("slow");
      });
    
      $("#p1").hover(function () {
      $("#p1").hide("slow");
      });
    
      $("#img2").mouseover(function () {
      $('#p2').show("slow");
      });
    
      $("#p2").hover(function () {
      $("#p2").hide("slow");
      });
    
      $("#img3").mouseover(function () {
      $('#p3').show("slow");
      });
    
      $("#p3").hover(function () {
      $("#p3").hide("slow");
      });
    
      $("#img4").mouseover(function () {
      $('#p4').show("slow");
      });
    
      $("#p4").hover(function () {
      $("#p4").hide("slow");
      });
    
      $("#img5").mouseover(function () {
      $('#p5').show("slow");
      });
    
      $("#p5").hover(function () {
      $("#p5").hide("slow");
      });
    });
    

    Also you can pass two functions two your hover handler to handle both mouseover and mouseout events. I think that'll shorten your code a bit. ;)

提交回复
热议问题