zoukankan      html  css  js  c++  java
  • 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>



     
      




  • 相关阅读:
    Vuex核心属性(上)
    layui 将json字符串以表格的形式展现出来
    Vue 路由懒加载 和 路由导航守卫
    jq遍历服务器发送过来的json字符串
    前端的发展
    关于定义函数的几种方式 及(箭头函数)
    js 子页面获取父页面的值
    关于数组的响应式方法和非响应式方法
    python3 -- random 模块
    多任务编程 -- multiprocessing 模块(创建多进程、进程池使用、进程间通信)
  • 原文地址:https://www.cnblogs.com/wang3680/p/dff502fd6f94286e4471686cbd35f022.html
Copyright © 2011-2022 走看看