H5^Study

JS基础学习:DOM

2019-04-08  本文已影响0人  Merbng

BOM

页面中所有的内容都是属于浏览器的,页面中的内容也都是window

window.location;

href /assign /reload

location.href = "http://www.jd.com";//属性
location.assign("http://www.jd.com"); //方法
location.reload();//刷新,重新加载
location.replace("http://www.jd.com");//没有历史记录

<script type="text/javascript">
            var locationObj = window.location;

            console.log("主机名及端口号:" + locationObj.host);
            console.log("地址:" + locationObj.href);
            console.log("端口号:" + locationObj.port);
            console.log("主机名:" + locationObj.hostname);
            console.log("文件的路径(绝对路径):" + locationObj.pathname);
            // 地址栏上面的#及后面的内容
            console.log("#及后面的内容:" + locationObj.hash);
            console.log("协议:" + locationObj.protocol);
            console.log("搜索的内容:" + locationObj.search);
        </script>
        <input type="button" name="" id="btn" value="跳转" />
        <script type="text/javascript">
            document.getElementById('btn').onclick = function() {
                // location.href = "http://www.jd.com";//属性
                // location.assign("http://www.jd.com"); //方法

                // location.reload();//刷新,重新加载
                location.replace("http://www.jd.com");//没有历史记录
                
            };
        </script>

navigator对象

<script type="text/javascript">
            // 通过platform可以判断浏览器所在的系统平台类型
            console.log(window.navigator.platform);
            // 浏览器类型
            console.log(window.navigator.userAgent);
        </script>

定时器

// 参数1:函数
// 参数2:时间---毫秒
// 执行过程:页面加载完毕后,过了1秒,执行一次函数的代码,又过一秒,再执行函数
// 返回值:就是定时器的id值

var timeId = window.setInterval(function() {
alert("我就安静"); //断言
}, 1000);

//停止定时器
// 参数:要清理的定时的id的值
window.clearInterval(timeId);

<input type="button" name="" id="btn" value="停止" />
        <script type="text/javascript">
            // 定时器
            // 参数1:函数
            // 参数2:时间---毫秒
            // 执行过程:页面加载完毕后,过了1秒,执行一次函数的代码,又过一秒,再执行函数
            // 返回值:就是定时器的id值
            var timeId = window.setInterval(function() {
                alert("我就安静"); //断言
            }, 1000);
            document.getElementById('btn').onclick = function() {
                //停止定时器
                // 参数:要清理的定时的id的值
                window.clearInterval(timeId);
            };
        </script>
上一篇 下一篇

猜你喜欢

热点阅读