目前,我使用 Javascript 替换与域相似的任何链接的一小部分(例如:othersite.com)我想知道如何在 JQUERY 中实现相同的效果。可能吗?我只想更改一小部分,而不影响链接的其余部分。因为我可以在 Jquery 中得到同样的结果(使用 Jquery)?我希望有人能帮忙,谢谢。
这是我的 Javascript 代码:
函数更改文本(){ var id = "乔希"; var link = document.getElementsByTagName('a'); var i = 链接长度; 当我 - ){ var lnk = 链接[i].href; 如果(lnk.match(“othersite.com”)){ 链接[i].href = lnk.replace(/name=[^&]*/g, 'name='+id); } } } 更改文本();
..
<a href="http://www.othersite.com/?name=susan1&last=3">Text</a>
<a href="http://www.othersite.com/?name=PAtrIck01&lat=6">Text</a>
<a href="http://www.othersite.com/?name=1Smith&lat=49">Text</a>
使用Javascript效果,如下:
<a href="http://www.othersite.com/?name=JOSH&last=3">Text</a>
<a href="http://www.othersite.com/?name=JOSH&lat=6">Text</a>
<a href="http://www.othersite.com/?name=JOSH&lat=49">Text</a>
因为我可以在 Jquery 中得到同样的结果(使用 Jquery)?...... 谢谢你。