我在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次。当鼠标进入同一链接时,它会执行两次,依此类推......
但我希望它只执行一次,即使鼠标输入两次或更多次。
答案 0 :(得分: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>";
}
});