-1

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回実行されることです.マウスが同じリンクに入ると、2回実行されます...

しかし、マウスが2回以上入力しても1回だけ実行したいです。

4

1 に答える 1

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>";

}

});

于 2013-08-08T10:06:23.520 に答える