js—BOM焦点事件

来源:互联网 发布:excel 下拉数据递增 编辑:程序博客网 时间:2024/04/30 17:23

js

<script>window.onload = function() {    var oText = document.getElementById('text1');    //onfocus : 当元素获取到焦点的时候触发    oText.onfocus = function() {        if ( this.value == '请输入内容' ) {            this.value = '';        }    }    //onblur : 当元素失去焦点的时候触发    oText.onblur = function() {        if ( this.value == '' ) {            this.value = '请输入内容';        }    }    /*        obj.focus() 给指定的元素设置焦点        obj.blur() 取消指定元素的焦点        obj.select() 选择指定元素里面的文本内容    */    oText.focus();    var oBtn = document.getElementById('btn');    oBtn.onclick = function() {        oText.select();    }}</script>
原创粉丝点击