doupeng6890 2016-11-17 16:56
浏览 173

如何仅在onmouseover上触发AJAX请求

I have below script which shows values from search page onmouseover.

<script type="text/javascript">
    function preview(val) {
      $.ajax({
        type: "POST",
        url: "search.php",
        data:'id='+val,
        success: function(data){
            $(".ress").html(data);
        }
    });
   }
 </script>

html :

<div class="CVSearchResult" onmouseover="preview('1')">

search :

<?php echo $_POST['id']; ?> 

output for class .ress :

1

However I want to hide the output onmouseout as well. How can I do this? I mean just trigger the AJAX for mouse hover and hide if not hover.

  • 写回答

2条回答 默认 最新

  • doubian19900911 2016-11-17 16:59
    关注
    <div class="CVSearchResult" onmouseover="preview('1')" onmouseout="hide()">
    <script>
    function hide() {
        $(".ress").html('');
    } 
    </script>
    

    You are adding event handler when user move the mouse away from the element to trigger hide function.

    The hude function grab the result dom element(which can contain selected results from previous calls) and set the html to empty string.

    That way when you move away with the mouse the div element is cleared.

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制