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 = "请输入";
        }

    }

猜你喜欢

转载自www.cnblogs.com/TKOPython/p/12823087.html
今日推荐