在ajax成功后,cluetip不适用于首次点击活动元素

cluetip does not work for first click on live elements after ajax success

本文关键字:元素 活动 适用于 不适用 成功 ajax cluetip      更新时间:2023-09-26

在ajax成功后的实时元素上,下面来自cluetip的代码不适用于首次点击,除非它能顺利工作。第一次点击会有什么问题?

  $('a.load-local').live('click', function(event) {
     $('a.load-local').cluetip({
        width: 'auto',
        activation: 'click',
        local:true,
        sticky: true,
        arrows: true,
        positionBy:'bottomTop',
       cursor: 'pointer',
       closePosition: 'top',
       closeText: '<img src="images/close1.jpg" alt="close" width="16" height="16"         
        style="position:absolute; right:5px; top:0px;" />'
    });
    event.preventDefault();
  });

我真的不知道cluetip,但有可能第一次点击实际上是为点击的元素初始化cluetip吗,然后它正常工作?(即使你每次点击都会重新初始化它)

快速查看他们的演示页面http://plugins.learningjquery.com/cluetip/demo/建议cluetip方法进行初始化,而不是调用。

在您的代码中,每次单击锚a.load-local时,cluetip都会被初始化。在我看来,只需要以下代码,您可以将其添加到$('document').ready()

 $('a.load-local').cluetip({
        width: 'auto',
        activation: 'click',
        local:true,
        sticky: true,
        arrows: true,
        positionBy:'bottomTop',
       cursor: 'pointer',
       closePosition: 'top',
       closeText: '<img src="images/close1.jpg" alt="close" width="16" height="16"
       style="position:absolute; right:5px; top:0px;" />'
    });