• 给a标签herf属性赋值时,必须加http://


    新建一个web工程,FirstWeb,在其中新建一个页面:test.jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>test change herf</title>
      <script type="text/javascript"> 
         function changeHerf()
         {
            var a1 = document.getElementById("a1");
            a1.setAttribute("href","www.baidu.com");
            
            var a2 = document.getElementById("a2");
            a2.setAttribute("href","http://www.baidu.com");
         }
      </script>
    </head>
    <body onload="changeHerf()">
         <a herf="#" id="a1">点击我看看,不加http://</a>
         </br>
         <a herf="#" id="a2">点击我看看,添加http:/</a>
    </body>
    </html>

    访问该页面,点击a1时,页面跳转到:http://localhost:8888/FirstWeb/www.baidu.com

    点击a2时,页面跳转到www.baidu.com

    总结:

    动态修改a标签的herf属性时,记得在网址前加上http://

  • 相关阅读:
    poj 1026 Cipher
    python中的global
    基于DL的文本分类综述
    K近邻算法学习
    聚类评价指标学习
    pytorch自动求导学习
    反向传播的推导
    二分搜索常用【转载】
    《Attention is all you need》论文学习
    5-28日|5-30日
  • 原文地址:https://www.cnblogs.com/king1302217/p/3246927.html
Copyright © 2020-2023  润新知