Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery附加到链接_Jquery_Wordpress_Permalinks - Fatal编程技术网

使用jquery附加到链接

使用jquery附加到链接,jquery,wordpress,permalinks,Jquery,Wordpress,Permalinks,我需要在指向某个URL的所有链接的末尾附加一个关联ID 这是我的东西,但我没法用 (这将在WordPress中显示) jQuery(文档).ready(函数(){ jQuery(“a[href*=doitbest]”。单击(函数(){ 追加(“?memberid=5705&associate=true”); }); }); 有什么想法吗?首先,我认为您必须使用$(this)而不是this 您还希望更改链接的URL。应更改href属性,因此 $('a#my_link').click( fun

我需要在指向某个URL的所有链接的末尾附加一个关联ID

这是我的东西,但我没法用

(这将在WordPress中显示)


jQuery(文档).ready(函数(){
jQuery(“a[href*=doitbest]”。单击(函数(){
追加(“?memberid=5705&associate=true”);
});
});

有什么想法吗?

首先,我认为您必须使用
$(this)
而不是
this

您还希望更改链接的URL。应更改href属性,因此

 $('a#my_link').click( function (event) {
  $(this).attr('href', $(this).attr('href') + '&id=1');
});

首先,我认为您必须使用
$(this)
而不是
this

您还希望更改链接的URL。应更改href属性,因此

 $('a#my_link').click( function (event) {
  $(this).attr('href', $(this).attr('href') + '&id=1');
});

假设您的选择器(
a[href*=doitbest]
)工作正常,您可以尝试:

jQuery(document).ready(function() {
   jQuery("a[href*=doitbest]").click(function() {
      href = $(this).attr('href');
      del = href.indexOf('?') > -1 ? '&' : '?';
      href += del + 'memberid=5705&associate=true';
      $(this).attr('href', href);
   });
});

这将更改
href
属性,而不是链接文本。不过,我不完全确定这是否是你想要的。
del
变量用于通过
&
字符来附加URL部分。

假设选择器(
a[href*=doitbest]
)工作,您可以尝试:

jQuery(document).ready(function() {
   jQuery("a[href*=doitbest]").click(function() {
      href = $(this).attr('href');
      del = href.indexOf('?') > -1 ? '&' : '?';
      href += del + 'memberid=5705&associate=true';
      $(this).attr('href', href);
   });
});

这将更改
href
属性,而不是链接文本。不过,我不完全确定这是否是你想要的。
del
变量用于通过
&
字符来附加URL部分。

这不起作用,但我忘了提到我试图附加的链接来自我显示在屏幕上的RSS提要。这有什么不同吗?@Adam Munns可能是-如果链接在连接单击处理程序时不是DOM的一部分,则不会有
href
被操纵。请发布更多代码或链接到现场演示。另外,尝试在
click
函数中放置一个简单的
警报()
,以查看处理程序是否正确连接。如何判断解析的RSS提要是否是DOM的一部分?警报似乎没有任何作用。您需要查看哪些代码?我将尝试同时获得一个实时版本嘿,各位,我决定用PHP来修改提要。这不起作用,但我忘了提到我试图附加到的链接来自我正在屏幕上显示的RSS提要。这有什么不同吗?@Adam Munns可能是-如果链接在连接单击处理程序时不是DOM的一部分,则不会有
href
被操纵。请发布更多代码或链接到现场演示。另外,尝试在
click
函数中放置一个简单的
警报()
,以查看处理程序是否正确连接。如何判断解析的RSS提要是否是DOM的一部分?警报似乎没有任何作用。您需要查看哪些代码?我将尝试在同时获得一个实时版本,我决定使用PHP来修改提要。