<a id="test" href="www.baidu.com" target="....">
--- js代碼
var href = $("#test").attr("href")
window.open(open) 雖然可以實現加載,但是會在瀏覽器打開一個新頁面,無法實現a標籤的target屬性。
location.href = href 當前頁跳轉 同樣無法實現target屬性
$("#test").click(); 無法實現
實現方法:
$("#test")[0].click();
用這個方法可以直接模擬點擊href的效果,實現下載。
因爲a標籤的href屬性是在他dom中的0裏面,需要點擊那個0才能實現,而數字型的屬性名不能用“.”來獲取,故寫成[0]。