我想檢查href屬性,如果它不包含完整路徑,我想用完整的URL替換它?我應該使用JavaScript,但不適用於IE 8?如何檢查href屬性,如果需要添加完整的url地址?
我的JS:
fullUrl = $(this).filter('[href^='+document.location.protocol+']').attr('href')
? true : false;
url = fullUrl ?
$(this).filter('[href^='+document.location.protocol+']').attr('href')
: document.location.protocol + '//' + document.domain + $(this).attr('href');
我需要檢查,如果HREF包含完整的URL或不:
HREF: 「/path/other.html」(部分)
href:「http://domain.com/path/other.html」(完整網址)
然後,如果我有部分網址href,我必須添加域並重新創建href到完整的URL!
您的代碼不會取代'href'屬性... –