jquery 获得焦点的时候,焦点时文本框清空,失去焦点时又显示默认文字

    xiaoxiao2021-03-26  37

     <p> <input type="text" class="input" name="name" value="姓名NAME:""/></p>

    $(document).ready(function() {

        //each遍历文本框     $(".input").each(function() {         //保存当前文本框的值         var vdefault = this.value;         $(this).focus(function() {             //获得焦点时,如果值为默认值,则设置为空             if (this.value == vdefault) {                 this.value = "";             }         });         $(this).blur(function() {             //失去焦点时,如果值为空,则设置为默认值             if (this.value == "") {                 this.value = vdefault;             }         });     }); });
    转载请注明原文地址: https://ju.6miu.com/read-664328.html

    最新回复(0)