-1

カーソルを合わせると、テキスト ファイルが表示されます。私が現れていないときは、消えてほしい。どうすればこれを行うことができ、私のコードはどのように見えるべきですか?

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script>
$(document).ready(function(){
   $(".button").hover(function(){ $.ajax({url:"demo_test.txt", success:function(result){ $("#div1").html(result); }}); }); 
});
</script>
</head>

<body>
   <div id="div1"></div>
<a href="#" class="button">Hover me</a> 
</body>

</html>
4

4 に答える 4

0

これを使って

$(document).ready(function(){
  $(".button").mouseenter(function () { 
    // run the ajax request and load the file..
  });
  $('.button').mouseleave(function () {
    // run the code here such as $('#div1').hide() or .css('display', 'none');
  });
});

これにより、ボタンから mouseleave のイベントが発生すると、オブジェクトが非表示になります。

そのためのフィドル:

http://jsfiddle.net/afzaal_ahmad_zeeshan/SfVrn/1/

于 2013-10-19T16:14:27.103 に答える