document.location的用法实例

<html>
     <head>
         <title>document.location </title>
     </head>
     <body>
         <b>document.location使用举例 </b ><p>
          <script type ="text/javascript"> 
       
             document.write( " 当前位置: " + document.location + " <p> " );
             document.write( " 当前位置的url路径: " + document.location.pathname + " <p> " );    
             document.write( " 当前位置的url协议: " + document.location.protocol + " <p> " );
             document.write( " 当前位置的url端口: " + document.location.port + " <p> " );
             // 设置新的location 
             //document.location.href= " http://www.baidu.com " ;
             window.open('http://www.baidu.com');
          </script>
     </body>
 </html> 

运行后,打印结果是:

document.location使用举例

当前位置: http://localhost/yacol/js/document.html

当前位置的url路径: /yacol/js/document.html

当前位置的url协议: http:

当前位置的url端口:

     document.location.href= " http://www.baidu.com " ;//转到百度
            window.open('http://www.baidu.com');//在新窗口打开百度

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以上是一个使用 Vue.js 框架构建的前端页面的代码,主要实现了页面元素的绑定、数据的加载和事件的绑定等功能。下面对其中的代码进行详细解释: ``` new Vue({ el: '#app', // 绑定 Vue 实例到 HTML 元素 #app 上 data: { // 定义 Vue 实例中的数据 self: '', userName: '' }, created: function() { // 在 Vue 实例创建时执行的函数 self = this; // 将 Vue 实例保存到 self 变量中 this.userName = getQueryString('userName'); // 获取 URL 中的 userName 参数并保存到 Vue 实例的 data 属性中的 userName 中 console.log(this.userName); this.load(); // 调用 load 方法加载数据 }, methods: { // 定义 Vue 实例中的方法 goout: function() { // 定义跳转页面的方法 window.location.href = 'login.html'; }, displayMethod: function(index) { // 定义切换按钮样式的方法 var btnss = document.getElementsByClassName('itemss'); for (var i = 0; i < btnss.length; i++) { var btn = btnss[i]; btn.style.background = '#6B05A5'; } btnss[index - 1].style.background = '#6B05A5'; }, load: function() { // 定义数据加载方法 // 在这里调用接口或者发送请求,加载数据 } } }) ``` 以上代码中,`data` 属性用于定义 Vue 实例中的数据,`created` 方法用于在 Vue 实例创建时执行一些初始化操作,`methods` 属性用于定义 Vue 实例中的方法。其中,`goout` 方法用于跳转页面,`displayMethod` 方法用于切换按钮样式,`load` 方法用于加载数据。在 `created` 方法中,通过调用 `getQueryString` 函数获取 URL 中的参数值,然后将其保存到 Vue 实例的 `userName` 属性中,以便在页面中使用。 总的来说,以上代码实现了一个简单的 Vue.js 页面,包含了数据绑定、事件绑定和方法定义等功能,可以通过调用接口或者发送请求来加载数据,实现前端页面的交互效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值