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();
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步