js、jq点击事件触发a链接跳转页面

482 阅读1分钟

话不多说直接上代码:

方法1:使用window.location.href就可以实现 

    $('#btn').click(function () {
        window.location.href="apiIndex/replyProblem.html"
    })

方法二:

 var a = document.createElement('a');
 a.setAttribute('href', "apiIndex/replyProblem.html);
 a.setAttribute('target', '_self');
// 防止反复添加
 if(document.getElementById('startTelMedicine')) {
     document.body.removeChild(document.getElementById('startTelMedicine'));
 }
   document.body.appendChild(a);
   a.click();