[英]Add a string at the end of url
我在網站上有各種鏈接,並希望在每個URL的末尾添加一個特定的字符串,該URL中包含一個域example.com。 例如:域為example.com的所有url在“ mystring”末尾都有一個字符串,因此完整的URL為: example.com?mystring
?mystring。 我正在嘗試完成此操作,以便可以在URL末尾生成keybuilder字符串。
樣本HTML結構: JsFiddle
這可能嗎? 謝謝
您可以嘗試如下
$(function(){
//iterate all a tag having href="example.com"
$('ul li a[href="example.com"]').each(function(){
//set href with new value
$(this).attr('href',$(this).attr('href')+'?myString');
});
});
內容 :
$('ul li a').click(function(){
var domain=$(this).attr('href');
alert(domain+'?myString');
});
$('a[href^="example.com"]').each(function(){
var href = $(this).attr('href');
$(this).attr('href', href + '?myString');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.