2012-08-02 70 views
1

我有以下使用qtip库创建一个JavaScript弹出的JavaScript。我不确定如何访问集合中的哪个li元素被点击。 这可能吗?我在下面的代码中添加了一个警告框来帮助解释问题。需要帮助请叫我! 非常感谢,jquery popup需要知道哪个元素导致事件

$('li').each(function() { 
    $(this).qtip(
    { 
     content: { 
      text: 'test text', 
      title: { text: true, button: '<img src="/Images/close.gif">' } 
    }, 
    position: { 
     corner: { 
      target: 'rightMiddle', 
      tooltip: 'leftMiddle' 
     }, 
     adjust: { 
      screen: true 
     } 
    }, 
    show: { 
     when: 'click', 
     solo: true 
    }, 
    api: { 
     beforeShow: function(index) { 
      if(document.getElementById('basketCheck')) { 
       alert('what LI caused this click?'); 
       return false; 
      } 
     } 
    }, 
    hide: 'unfocus', 
    style: { 
     tip: true, 
     border: { 
      width: 0, 
      radius: 4, 
     }, 
     width: 264, 
     height: 195, 
     title: { 
      background: '#ffffff' 
     }, 
     lineHeight: '16px' 
    } 
}) 

});

+0

作为一个说明,对于'beforeShow'传递一个事件作为参数的回调函数;称'索引'没有意义。 – 2012-08-02 10:02:23

回答

0

触发元素在qTip实例的elements.target属性中可用。该实例又势必thisbeforeShow处理程序:

api: { 
    beforeShow: function() { 
     if(document.getElementById('basketCheck')) { 
      // This <li> caused the click. 
      var sourceElement = this.elements.target; 
      return false; 
     } 
    } 
} 
+0

谢谢! P – 2012-08-02 10:13:59

+0

我可以关闭sourceElement行之后的弹出窗口吗?谢谢 – 2012-08-02 10:18:12

+0

@詹姆斯,当然,'this.hide()'应该做到这一点。 – 2012-08-02 10:21:16

0

通过上下文this

beforeShow: function(index) { 
    //'this' points to the affected LI 
} 
相关问题