[英]Set MaxLength for dynamic <p>
我有允許顯示 Bing 搜索結果的腳本。 我可以這樣調用搜索結果 url:
'<p class="width"><a href="' , imgResult.Url , '">',imgResult.DisplayUrl,'</a></p>' ,
問題是有時 url 會長這樣的“草率”:
http://www.art-wallpaper.net/Game-Wallpapers/Assassins-Creed-Brotherhood/imagepages/image3.htm
我想“隱藏”或“刪除” url ( http://www.
) 的開頭,並從/Game...
: art-wallpaper.net
我有這樣做的(簡單)方法嗎?
也許像這樣的 JavaScript function。
function shorten(str)
{
// Get rid of the protocol
str = str.replace("http://", "");
str = str.replace("https://", "");
// Return the domain-part of the URL
return str.split("/")[0];
}
在打印之前將您的 URL 傳遞給 JavaScript function。
未經測試。
url="http://www.art-wallpaper.net/Game-Wallpapers/Assassins-Creed-Brotherhood/imagepages/image3.htm";
pathArray =url .split( '/' );
host = pathArray[2];
alert(host);// alert "www.art-wallpaper.net"
和,
pathArray = "http://www.art-wallpaper.net/Game-Wallpapers/Assassins-Creed-Brotherhood/imagepages/image3.htm".split( '/' );
host = pathArray[2].substring(4);
alert(host);// alert "art-wallpaper.net"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.