JS常用对象及函数

Window对象

//确认弹出框
confirm("您确定是否删除吗?");
//输入框
prompt("请输入价格");

History对象

<html>
    <head>
        <meta charset="UTF-8">
        <title>History对象</title>
        <script>
            function fanhui(){
                history.go(-1);
                //history.back();
                                //history.forward();
            }
        </script>
    </head>
    <body>
        <input type="button" value="返回上一页" onclick="fanhui()"/><br />
        <a href="03_Location对象.html">下一页</a>
    </body>
</html>

Location对象

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Location对象</title>
    </head>
    <body>
        <input type="button" value="跳转到history页面" onclick="javascript:location.href='02_History对象.html'"/>
    </body>
</html>

聚焦事件onfocus(昂for k 斯)

<script>
function showTips(id,info){
    document.getElementById(id+"span").innerHTML="<font color='gray'>"+info+"</font>";
    }
            
            
function check(id,info){
    //1.获取用户输入的用户名数据
    var uValue = document.getElementById(id).value;
    //2.进行校验
    if(uValue==""){
    document.getElementById(id+"span").innerHTML="<font color='red'>"+info+"</font>";
    }else{
        document.getElementById(id+"span").innerHTML="";
        }
}
</script>
<body>
<input type="text" name="user" size="34px" id="user" onfocus="showTips('user','用户名必填!')" onblur="check('user','   用户名不能为空!')"/><span id="userspan"></span>
</body>
                            
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容