我在jquery中遇到问题,我有以下代码,其中包含带有自定义内容的jquery-ui-tooltip。
$('a').tooltip({
items: "a ,[title]",
content: function() {
$('a').mouseenter(function(e) {
var tempid= $(this).attr('title');
console.log("hhh "+tempid);
$.ajax({
type:"POST",
url:"page1.php",
data:"id=tempid",
error:function(){
console.log(event);
return "<P>Some Problem occured</p>";
},
success:function(e){
console.log(event);
}
});
});
return "<p>ha hdj fj fkfod jf kjf ckfd fkj</p>";
}
})
现在的问题是,当鼠标在任何链接上输入时,成功部分将执行1次。当鼠标在同一链接上输入时,它将执行两次,依此类推...
但是我希望它即使鼠标输入两次或更多次也只能执行一次。
使用全局变量检查鼠标是否已经进入。
var hasNotEntered = true;
$('a').tooltip({
items: "a ,[title]",
content: function () {
$('a').mouseenter(function (e) {
if (hasNotEntered) {
var tempid = $(this).attr('title');
console.log("hhh " + tempid);
$.ajax({
type: "POST",
url: "page1.php",
data: "id=tempid",
error: function () {
console.log(event);
return "<P>Some Problem occured</p>";
},
success: function (e) {
console.log(event);
}
});
}
});
return "<p>ha hdj fj fkfod jf kjf ckfd fkj</p>";
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句