event事件和输入框练习

Posted tkopython

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了event事件和输入框练习相关的知识,希望对你有一定的参考价值。

<input class="keyword" type="text" value="请输入" onfocus="first()" onblur="ff()">
<script>
    var ky;
    function first() {
        // console.log("this is first1"); //焦点触发
        ky = document.getElementsByClassName("keyword")[0];
        if(ky.value ==="请输入"){
            ky.value="";
        }

    }

    function ff() {
        // console.log("this is first2"); //失去焦点触发
        if (ky.value.trim().length === 0) {
            ky.value = "请输入";
        }

    }



<script>
//要是script放在body上面那么就要在加上这个
window.onload=function () {

}
</script>
 

 

以上是关于event事件和输入框练习的主要内容,如果未能解决你的问题,请参考以下文章