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();
}
原文地址:https://www.cnblogs.com/syp1Blog/p/10938175.html