Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.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
Javascript jQuery:.attr to href如果DIV包含(';text';)?_Javascript_Jquery_Twitter_Contains_Attr - Fatal编程技术网

Javascript jQuery:.attr to href如果DIV包含(';text';)?

Javascript jQuery:.attr to href如果DIV包含(';text';)?,javascript,jquery,twitter,contains,attr,Javascript,Jquery,Twitter,Contains,Attr,(Twitter)我正在尝试但不确定如何在链接/A/href的开头使用此链接.attr,如果所选元素包含某些单词: $(".tweet:contains('government','Anonymous')").each(function(){ $old_url = $(this).attr('href'); $new_url = 'http://blankrefer.com/?'+$old_url; $(this).attr('href',$new_url); });

(Twitter)我正在尝试但不确定如何在链接/A/href的开头使用此链接.attr,如果所选元素包含某些单词:

 $(".tweet:contains('government','Anonymous')").each(function(){
   $old_url = $(this).attr('href');
   $new_url = 'http://blankrefer.com/?'+$old_url;
   $(this).attr('href',$new_url);
  });
这可以工作,但没有文本检测:

$("A").each(function(){
   $old_url = $(this).attr('href');
   $new_url = 'http://blankrefer.com/?'+$old_url;
   $(this).attr('href',$new_url);
});

无法将多个搜索字符串传递给
:contains
,有关详细信息,请参阅。可以使用逗号分隔符使用另一个搜索字符串重复选择器,如下所示

$(函数(){
$(“.tweet:contains('government'),.tweet:contains('Anonymous')).each(function(){
$old_url=$(this.attr('href');
警报($old_url);
$new\u url='1http://blankrefer.com/?'+$old_url;
$(this.attr('href',$new\u url);
});
});


您能再解释一下您的问题是什么吗?jfyi:
$(“a”).attr(“href”,function(idx,oldValue){return'http://blankrefer.com/?'+oldValue;})
与您的第二个示例相同:)并且使用Andreas的示例,您可以在return函数中使用if contains来返回原始的或修改过的URL。它仍然不能与word detection@andreassoming一起工作吗$(function(){$(“.tweet:contains('Anonymous')”).each(function(){$('a”).attr(“href”,function(idx,oldValue){return'?'+oldValue;});});单击上面的“运行代码片段”按钮后,您将只收到href的匹配链接警报。为什么它在您的案例中不起作用?我是否错误地理解了您的问题?在浏览器上检查控制台错误,或在JSFIDLE链接上重新创建问题并与我共享