• javaScript 通过location对象获取项目的url


    项目中有些要通过jQuery 动态加载,其中需要一些路径,使用相对路径会出现错误,报

    $("#t1").html("设置或返回从井号 (#) 开始的 URL(锚)---" + location.hash);
    $("#t2").html("设置或返回主机名和当前 URL 的端口号---" + location.host);
    $("#t3").html("设置或返回当前 URL 的主机名--" + window.location.hostname);
    $("#t4").html("设置或返回完整的 URL---" + window.location.href);
    $("#t5").html("设置或返回当前 URL 的路径部分---" + window.location.pathname);
    $("#t6").html("设置或返回当前 URL 的端口号---" + window.location.port);
    $("#t7").html("设置或返回当前 URL 的协议---" + window.location.protocol);
    $("#t8").html("设置或返回从问号 (?) 开始的 URL(查询部分)---" + window.location.search);

    结果

  • 相关阅读:
    Event bubbling
    input/change event practice
    Form event
    Event_Object
    DOM_this keyword
    Random color generator exercise
    DOM_events_addEventListener
    Spring值SpEL
    Spring之使用外部属性文件
    Spring之Bean的作用域
  • 原文地址:https://www.cnblogs.com/hjyhjyhjy/p/6432523.html
Copyright © 2020-2023  润新知