如何使用 QTip 访问触发元素?
我有一个 QTip 分配给一个元素,如下所示:
$('#myDiv').qtip({
show: { when: { event: 'click', } },
hide: { when: { event: 'unfocus' } },
style: {
border: {
width: 5,
radius: 10
},
padding: 10,
textAlign: 'center',
tip: true, // Give it a speech bubble tip with automatic corner detection
name: 'red' // Style it according to the preset 'cream' style
},
position: {
corner: {
tooltip: 'topMiddle', // Use the corner...
target: 'bottomMiddle' // ...and opposite corner
}
},
content: {
text: self.parent('.qtip').html(),
title: { text: 'My Title' }
},
});
在“内容”中的“文本”下,我试图访问触发此 QTip 在单击后出现的元素的 innerHTML。
但是,我当前的 self.parent('.qtip').html()
方法(如上所示)不起作用。
执行此操作的标准方法是什么?谢谢。
I have a QTip assigned to an element as follows:
$('#myDiv').qtip({
show: { when: { event: 'click', } },
hide: { when: { event: 'unfocus' } },
style: {
border: {
width: 5,
radius: 10
},
padding: 10,
textAlign: 'center',
tip: true, // Give it a speech bubble tip with automatic corner detection
name: 'red' // Style it according to the preset 'cream' style
},
position: {
corner: {
tooltip: 'topMiddle', // Use the corner...
target: 'bottomMiddle' // ...and opposite corner
}
},
content: {
text: self.parent('.qtip').html(),
title: { text: 'My Title' }
},
});
Under 'text' in 'content', I am trying to access the innerHTML of the element that triggered this QTip to appear after being clicked on.
However, my current means of self.parent('.qtip').html()
, as displayed above, is not working.
What is the standard way to do this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
后来我找到了这个问题的答案。
要访问触发 QTip 的元素的属性,必须以这种方式构造代码:
这样,就可以使用 $(this) 来访问触发 QTip 的元素的数据,例如innerHTML。
I later found the solution to this question.
To access properties of the element that triggered the QTip, one must structure the code in this way:
That way, one can use $(this) to access data such as innerHTML of the element that triggered the QTip.
也许你可以之前设置它:
并在对象内部使用它:
Maybe you could set it before:
And use it inside the object: