$(".img").hover( function () { var dom = $(this).siblings('.PopupWindow'); var ccssbh = dom.children('span').text(); var divDom = dom.children('div'); $.ajax({ success: function (result) { divDom.html(''); var data = result.data.data; var domHtml = <div class=PopupWindow_top> + <span> + data.mc + </span> + </div> domHtml += <div class=PopupWindow_bottom> + <div class=PopupWindow_bottom_item>+ <span> + 配 + </span> + <span> + data.pqname + "</span> + </div>" + "<div class="PopupWindow_bottom_itemt">" + "</div>" divDom.append(domHtml); dom.removeClass('PopupWindowNone'); dom.addClass('PopupWindowblock'); }, function () { var dom = $(this).siblings('.PopupWindow'); dom.removeClass('PopupWindowblock'); dom.addClass('PopupWindowNone'); 修改hover鼠标能够放在在PopupWindow里面
时间: 2024-03-12 16:43:19 浏览: 75
可以将鼠标移入事件绑定到 ".PopupWindow" 元素上,而不是 ".img" 元素上。具体来说,可以修改代码如下:
```
$('.PopupWindow').hover(function () {
var dom = $(this);
var ccssbh = dom.children('span').text();
var divDom = dom.children('div');
$.ajax({
success: function (result) {
divDom.html('');
var data = result.data.data;
var domHtml = '<div class="PopupWindow_top"><span>' + data.mc + '</span></div>';
domHtml += '<div class="PopupWindow_bottom"><div class="PopupWindow_bottom_item"><span>配</span><span>' + data.pqname + '</span></div><div class="PopupWindow_bottom_itemt"></div></div>';
divDom.append(domHtml);
dom.removeClass('PopupWindowNone');
dom.addClass('PopupWindowblock');
},
error: function () {
dom.removeClass('PopupWindowblock');
dom.addClass('PopupWindowNone');
}
});
}, function () {
var dom = $(this);
dom.removeClass('PopupWindowblock');
dom.addClass('PopupWindowNone');
});
```
这样,当鼠标移入 ".PopupWindow" 元素时,就会触发 Ajax 请求,获取数据并更新弹出框内容;当鼠标移出 ".PopupWindow" 元素时,就会隐藏弹出框。