a标签

作者: Rella7 | 来源:发表于2018-04-24 09:28 被阅读0次

    JavaScript 如何跳转页面?

    // 跳转
    window.location.replace('https://www.awesomes.cn') // 不将被跳转页面加入浏览器记录
    window.location.assign('https://www.awesomes.cn')
    window.location.href = 'https://www.awesomes.cn'
    window.location = 'https://www.awesomes.cn'

    // 返回上一页
    window.history.back()
    window.history.go(-1)

    // 刷新当前页
    window.location.reload()

    在a中调用js函数

    <a href="javascript:void(0);" onclick="js_method()"></a>  
    <a href="javascript:;" onclick="js_method()"></a>  
    <a href="#" onclick="js_method();return false;"></a>  
    

    <a>标签传值和获取值

    //传值的形式
    <a href="地址?参数名=值"></a>,多个参数用&隔开
    <a href="地址?参数1=值&参数2=值"></a>
    例:<a href="test.asp?a=1&b=2&c=3"></a>

    //修改值
    var 变量 = 值;
    document.getElementById("id名").href="地址?参数="+变量;

    <a href="" id="n" onclick="t()"></a>  
    
    function t() {
        //可以是一个可变的值  
        var name = "张三"; 
        var id = 13527892092;
        var age = 25;
    
        //用javascript的方法改变href属性值,从而传递可变参数  
        document.getElementById("n").href = "a.jsp?name=" + name;
    
        //用jquery的方法改变href属性值,从而传递可变参数
        $(this).attr("href", "a.jsp?name=" + name + "&id=" + id + "&age=" + age); 
    }
    

    //获取上个页面跳转过来获取当前的参数

    //获取地址栏参数,name:参数名称
     function getUrlParms(name){
       var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
       var r = window.location.search.substr(1).match(reg);
       if(r!=null)
       return unescape(r[2]);
       return null;
       }
    var id = getUrlParms("id");
    
    function getRequest() {
      var url = window.location.search; //获取url中"?"符后的字串
      var theRequest = new Object();
      if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
           
          theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
           
        }
      }
      return theRequest;
    }
    var id= getRequest().id;
    

    相关文章

      网友评论

          本文标题:a标签

          本文链接:https://www.haomeiwen.com/subject/ntydlftx.html