我有一个列表项
<ul><li id='1'>Testing</li></ul>
我想将此元素 (1) 的 ID 传递给 jquery 片段。例如:
$('#homepage li').qtip({
content: {
url: 'testsite.php?id=!!!THIS IS WHERE THE ID SHOULD BE PASSED!!!',
method: 'get'
},
show: 'mouseover',
hide: 'mouseout',
})
有什么想法吗?
最佳答案
您需要使用 .each()
在这里,您可以在设置时引用该元素,如下所示:
$('#homepage li').each(function() {
$(this).qtip({
content: {
url: 'testsite.php?id=' + this.id,
method: 'get'
},
show: 'mouseover',
hide: 'mouseout'
});
});
请注意,您的纯数字 ID 仅在 HTML4 中有效(尽管它们在 HTML5 中没问题)。
关于php - 将参数传递给 Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4284296/