使用jquery在页面中更新选定的href值
使用jquery更新页面中的所有href值。 我有href=”http://www.google.com“从页面出来后,我想将上面提到的href更新为”“如何完成此操作使用jquery在页面中更新选定的href值,jquery,Jquery,使用jquery更新页面中的所有href值。 我有href=”http://www.google.com“从页面出来后,我想将上面提到的href更新为”“如何完成此操作 $('[href]').each(function () { $(this).attr('href', 'http://www.test.com'); }); 选择器将使用*=遍历其href属性中包含google的所有链接,如果是,它将相应地更新其属性。将此保存为.html文件,以获得完整的工作示例 <html>
$('[href]').each(function () {
$(this).attr('href', 'http://www.test.com');
});
选择器将使用
*=
遍历其href
属性中包含google
的所有链接,如果是,它将相应地更新其属性。将此保存为.html文件,以获得完整的工作示例
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a[href*='http://www.google.com']").attr('href','http://www.test.com').html('Test.com');
});
</script>
</head>
<body>
<a href="http://www.google.com">Google</a>
<a href="http://www.google.com">Google</a>
<a href="http://www.google.com">Google</a>
<a href="http://www.NotGoogle.com">Not Google</a>
</body>
</html>
$(文档).ready(函数(){
$(“a[href*=”http://www.google.comattr('href','http://www.test.comhtml('Test.com');
});
使用选择器
<script type="text/javascript">
$("a[href*='http://www.google.com']").attr('href','http://www.test.com');
</script>
$(“a[href*=”http://www.google.comattr('href','http://www.test.com');
我想在这里看到更多的澄清和细节,因为您的措辞不能完全理解您想要的行为。根据您的要求,使用出站URL重写规则可能更好。
<script type="text/javascript">
$("a[href*='http://www.google.com']").attr('href','http://www.test.com');
</script>