我有一个像这样的父div标签
<div class="top-news-heading">Top News Items<br>
<ul>
<li>
<div id="xlaANMzone_4f503f">
<div id="4f503f">
<div align="left" style="width: 100%; padding: 0px; margin: 0px;">
<a href="http://www.onesite.com.au/news_manager/templates/?a=1231&z=44"> News 1</a><br>
<a href="http://www.onesite.com.au/news_manager/templates/?a=1232&z=44"> News 2</a><br>
<a href="http://www.onesite.com.au/news_manager/templates/?a=1233&z=44"> News 2</a><br>
</div>
</div>
</div>
</li>
<li>
<div id="xlaANMzone_4f503f">
<div id="4f503f">
<div align="left" style="width: 100%; padding: 0px; margin: 0px;">
<a href="http://www.onesite.com.au/news_manager/templates/?a=1236&z=44"> News 4</a><br>
<a href="http://www.onesite.com.au/news_manager/templates/?a=1238&z=44"> News 5</a><br>
<a href="http://www.onesite.com.au/news_manager/templates/?a=1230&z=44"> News 6</a><br>
</div>
</div>
</div>
</li>
</ul>
</div> <!--parent div ends-->
我想将每个子标记的href更改为http://www.offsite.com/article.asp/a=1238&z=44。使用jQuery或JavaScript ....
请注意,查询字符串“a”和“z”应该是原始字符串。任何帮助将不胜感激。
答案 0 :(得分:2)
$(document).ready(function(){
$(".top-news-heading a").attr("href","your_new_link");
});
答案 1 :(得分:1)
如果你只是想像我想的那样替换字符串
$('a').each(function(){
var $this = $(this);
$this.attr('href', $this.attr('href').replace(/onesite/, 'offsite'));
});