下面是页面加载后的html。
<div style="width: 960px;">
<a href="Alerts.htm" target="_blank">TEST 1</a>
<a href="blog.htm" target="_blank">TEST 2</a>
<a href="severe.htm" target="_blank">TEST 3</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要<a href="blog.htm" target="_blank">TEST 2</a>使用 jquery更改页面加载后的 href 值 。
我已经尝试了以下选项。但它没有用。任何建议/想法请...
试一试
$(a).attr("href", "http://the.new.url");
Run Code Online (Sandbox Code Playgroud)
尝试二
$('a[href*="blog.htm"]').attr('href', function(i,href) {
return href.replace('blog.htm', 'http://catbloguat.myblog.com');
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
you missed the document ready function.
$(document).ready(function() {
$('a[href*="blog.htm"]').attr('href' , 'http://catbloguat.myblog.com');
});
Run Code Online (Sandbox Code Playgroud)