Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 清除输入输出字段后丢失输入提示。。。有工作吗?_Javascript_Jquery_Input_Hints - Fatal编程技术网

Javascript 清除输入输出字段后丢失输入提示。。。有工作吗?

Javascript 清除输入输出字段后丢失输入提示。。。有工作吗?,javascript,jquery,input,hints,Javascript,Jquery,Input,Hints,我有两个脚本用于清除表单和使用输入提示。执行清除功能后,输入提示不会返回 function clear_form_elements(ele) { $(ele).find(':input').each(function() { switch(this.type) { case 'password': case 'select-multiple': case 'select-one': case 'text': case 'textarea':

我有两个脚本用于清除表单和使用输入提示。执行清除功能后,输入提示不会返回

function clear_form_elements(ele) {

$(ele).find(':input').each(function() {
switch(this.type) {
    case 'password':
    case 'select-multiple':
    case 'select-one':
    case 'text':
    case 'textarea':
        $(this).val('');
        $("  .bx4a").removeAttr("style");
        $("  .bxTXTa").removeAttr("style");
        $("  .bxTXTa2").removeAttr("style");
        $("  .bx4a2").removeAttr("style");
        $("  .bx").removeAttr("style");
        $("  .ts").removeAttr("style");
        $("  .button-toggle-on").removeAttr("style");
        $("  .gnM").removeAttr("style");
        $("  .gnF").removeAttr("style");
        break;
    case 'checkbox':
    case 'radio':
        this.checked = false;
   }
  });

 }






 // jQuery Input Hints plugin
 // Copyright (c) 2009 Rob Volk
 // http://www.robvolk.com

jQuery.fn.inputHints=function() {
// hides the input display text stored in the title on focus
// and sets it on blur if the user hasn't changed it.

// show the display text
$(this).each(function(i) {
    $(this).val($(this).attr('title'))
        .addClass('hint');
});

// hook up the blur & focus
return $(this).focus(function() {
    if ($(this).val() == $(this).attr('title'))
        $(this).val('')
            .removeClass('hint');
}).blur(function() {
    if ($(this).val() == '')
        $(this).val($(this).attr('title'))
            .addClass('hint');
});
};

$(document).ready(function() {$('input[title],textarea[title]').inputHints();});

提示文本的策略非常简单:将输入的默认值设置为所需的提示文本,然后在获得焦点时将该值设置为。然后onblur,如果该值仍然为,则将该值设置为默认值。e、 g

<label for="userName">Name:<input name="userName" id="userName"
 value="Your full name&hellip;" class="hint"></label>

<script>
function hintFocus() {
  if (this.value == this.defaultValue) this.value = '';
}
function hintBlur(el) {
  if (this.value == '') this.value = this.defaultValue;
}

// Add the listeners
var el = document.getElementById('userName');
el.onfocus = hintFocus;
el.onblur = hintBlur;
</script>

为表单使用一个标准的重置按钮,并为其提供一个侦听器,以便在表单重置时添加提示类,以适当地输入type text和textarea。

我认为RobG的答案中存在一个错误,如果用户键入的文本与hintYour全名完全相同…,然后单击某个位置并单击输入,然后用户输入的内容将消失