zoukankan      html  css  js  c++  java
  • javascript的DOM操作

    <html>
    <script type="text/javascript">
    
        //window下history属性
    
        /*一共查看这个页面一共点击的几个页面
        document.write(history.length);
    
        //打开上一个页面
    
        history.back();
    
        //打开下一个页面
    
        history.forward();
    
        //history.go(-1) 等价于history.back();
    
        //history.go(1) 等价于history.forward();
    
        //window下location属性
    
        //hash 属性是一个可读可写的字符串,该字符串是 URL 的锚部分(从 # 号开始的部分)。
    
        //假设当前的 URL 是: http://example.com:1234/test.htm#part2
        document.write(location.hash);   输出//#part2
    
        //host 属性是一个可读可写的字符串,可设置或返回当前 URL 的主机名称和端口号。
    
        //当前地址是 http://localhost/js/dom/03.html
        document.write(location.host);        //localhost
        
        //hostname 属性是一个可读可写的字符串,可设置或返回当前 URL 的主机名。
    
        //当前地址是 http://localhost/js/dom/03.html
        document.write(location.hostname);    //localhost
    
        //href 属性是一个可读可写的字符串,可设置或返回当前显示的文档的完整 URL。因此,我们可以通过为该属性设置新的 URL,使浏览器读取并显示新的 URL 的内容。
    
        document.write(location.href);        //http://localhost/js/dom/03.html
        location.href = 'http://www.baidu.com';    //直接显示'http://www.baidu.com'这个链接的内容
    
        //pathname 属性是一个可读可写的字符串,可设置或返回当前 URL 的路径部分。
    
        document.write(location.pathname);    //  "/js/dom/03.html"
    
        //port 属性是一个可读可写的字符串,可设置或返回当前 URL 的端口部分。
    
        //假设当前的 URL 是: http://example.com:1234/test.htm#part2
        document.write(location.port);            //1234
        
    
        //protocol 属性是一个可读可写的字符串,可设置或返回当前 URL 的协议。
    
        document.write(location.protocol);        //http:   
       
    
        //search 属性是一个可读可写的字符串,可设置或返回当前 URL 的查询部分(问号 ? 之后的部分)。
    
        //URL是:http://localhost/js/dom/03.html%20?aa=123
        document.write(location.search);        //?aa=123
    
        
        //assign() 方法可加载一个新的文档。
    
        function aa(){
            window.location.assign('http://www.baidu.com');     //跳转到百度页面
        }
    
        //reload() 方法用于重新加载当前文档。
    
        function aa(){
            location.reload();                //刷新文档
        }
    
        //replace() 方法可用一个新文档取代当前文档。
    
        function aa(){
            location.replace('http://www.baidu.com');
        }
        
        window下的方法
    
        //alert() 方法用于显示带有一条指定消息和一个 OK 按钮的警告框。
        alert('123');        //123
    
        
        //confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框。
    
        var r = confirm('1231314');
        if(r == true){
    
            alert('123');  //点击确定后执行
        }else{
    
            alert('456');  //点击取消后执行
        }
    
        //print() 方法用于打印当前窗口的内容。
    
        window.print();
    
       
        //prompt 方法用于显示可提示用户进行输入的对话框。
    
        var name = prompt('sdfsdfsdf','');
        alert(name);        //打印的是你所输入的信息
        
    
        //setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。
        //setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。
    
        //clearInterval() 方法可取消由 setInterval() 设置的 timeout。
        //clearInterval() 方法的参数必须是由 setInterval() 返回的 ID 值。
    
    
        var int = setInterval('bb()',3000);        //方法可按照指定的周期(以毫秒计)来调用函数或计算表达式
    
        function bb(){
            alert('123');
        }
    
        function cc(){
    
            window.clearInterval(int);            // 方法可取消由 setInterval() 设置的 timeout。                                            //    方法的参数必须是由 setInterval() 返回的 ID 值
        }
        
        */
    </script>
    
    <a onclick="aa()">点击</a>
    <a onclick="cc()">停止</a>
    </html>



  • 相关阅读:
    Vagrant命令
    您必须知道的 Git 分支开发规范
    phpstorm的提速设置
    Flex 布局教程:语法篇
    Bootstrap 3 & 4 的多级下拉菜单示例
    申请快递查询100接口
    vue.js组件与组件之间的通信
    MAMP环境下 cookie无法正常使用
    Git 常用命令
    Linux学习笔记之yum安装mysql5.7
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3211985.html
Copyright © 2011-2022 走看看