【问题标题】:Passing arguments to Jquery将参数传递给 Jquery
【发布时间】:2011-05-16 02:51:57
【问题描述】:

我有一个列表项

<ul><li id='1'>Testing</li></ul>

我想将此元素 (1) 的 id 传递给 jquery sn-p。例如:

$('#homepage li').qtip({
  content: {
  url: 'testsite.php?id=!!!THIS IS WHERE THE ID SHOULD BE PASSED!!!',
  method: 'get'
  },
  show: 'mouseover',
  hide: 'mouseout',
  })

有什么想法吗?

【问题讨论】:

  • 请注意 id=1 不是 w3c 有效的。你不能用数字开头的ID
  • @meo - 它在 HTML4 中无效,鉴于许多人采用/使用 HTML5,这是现在应该做出的明确区分。
  • 是的,这只是一个例子,计划在前面贴一个字母以使其有效。欢呼

标签: php jquery arguments


【解决方案1】:

您需要在此处使用.each(),以便在设置元素时引用该元素,如下所示:

$('#homepage li').each(function() {
  $(this).qtip({
    content: {
      url: 'testsite.php?id=' + this.id,
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
  });
});

请注意,您的仅数字 ID 仅在 HTML4 中有效(尽管它们在 HTML5 中很好)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 2010-09-27
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2011-04-16
    • 2017-02-05
    相关资源
    最近更新 更多