js函數模擬實現a標簽的點擊實現href


//js函數實現模擬a標簽的href

//創建a標簽,設置屬性,點擊
function js_a_href(){ var a = document.createElement('a'); a.setAttribute('href', 'http://www.XXX.com'); a.setAttribute('target', '_blank'); a.setAttribute('id', 'js_a'); //防止反復添加 if(document.getElementById('js_a')) { document.body.removeChild(document.getElementById('js_a')); } document.body.appendChild(a); a.click(); }


//或者隱藏一個a標簽,
<a href="http://www.XXX.com" id="hi_a"  style="display:none;"></a>

function hidden_a_href(){
  document.getElementById("hi_a").click();
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM