JS、html打开超链接的几种形式

1、直接使用input在原有的标签页中直接打开一个页面,将原有标签页覆盖

在按钮中直接打开一个连接,这里不需要用到js的代码,根据HTML中的onclick属性


<input type="button" name="btnEdit" value="编辑" onclick="window.location.href='<?=base_url()?>index.php/admin/expert/expertEdit/<?=$expertId?>';" id="btnEdit" class="input" />

2、JS打开超链接的几种形式

  • window.open(”url”)        打开一个新的标签页

    $('#gradePaper').click(function(){
        window.open('<?=base_url()?>index.php/admin/search/searchAllByCode');
    });  

  • 用自定义函数

         <script>
         function openWin(tag,obj)
         {
             obj.target="_blank";
             obj.href = "Web/Substation/Substation.aspx?stationno="+tag;
             obj.click();
         }
        </script>

<a href="javascript:void(0)" onclick="openWin(3,this)">超链接</a>

  • window.location.href=””;     这种方式也是覆盖原有的标签页的方式打开

3、js和jquery控制超链接,使链接在子窗口打开

  • 这是用jquery,让其所有超链接在新窗口打开


<script type="text/javascript" src="JQuery/jquery-1.4.2.js"></script>
<script type="text/javascript">
     $(document).ready(function() {
           $("a").attr("target","_blank");
})
</script>

  • 用jquery,想让一部分超链接在新窗口打开,只要在基范围加个id就好了,比如:


<div id="ccc"><a href="index.html">首页</a></div> 
  <script type="text/javascript" src="JQuery/jquery-1.4.2.js"></script>
<script type="text/javascript">
     $(document).ready(function() {
           $("div#ccc a").attr("target","_blank");
})
</script>

 

  

来自为知笔记(Wiz)

原文链接:https://www.cnblogs.com/wang3680/p/dff502fd6f94286e4471686cbd35f022.html
本文来源 爱码网,其版权均为 原网址 所有 与本站无关,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源。

© 版权声明

相关文章