2012-04-14 5 views
0

Ich habe zwei Skripte zum Löschen meines Formulars und zur Verwendung von Eingabehinweisen. Die Eingabehinweise werden nicht zurückgegeben, nachdem ich die Löschfunktion ausgeführt habe.Verlust von Eingabehinweisen nach dem Löschen von Inout-Feldern ... irgendwelche Probleme?

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();}); 

Antwort

0

Die Strategie für Hinweistext ist wirklich einfach: der Standardwert des Eingangs auf den Hinweistext festgelegt, die Sie wollen, dann, wenn es den Wert auf ‚‘ setzt den Fokus erhält. Wenn onblur, wenn der Wert immer noch '' ist, setzen Sie den Wert auf den Standardwert. z.B.

<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> 

einen Standard Reset-Taste für das Formular verwenden, und es wird ein Listener geben, so dass es den Hinweis Klasse Eingabetyp Text und Textbereich (je nachdem) fügt, wenn das Formular zurückgesetzt wird.

0

Ich denke, es gibt einen Fehler in der Antwort von RobG, wenn der Benutzer genau den gleichen Tipp wie den Hinweis eingeben (Ihr voller Name & hellip;), dann und klicken Sie irgendwo und klicken Sie auf die Eingabe, dann was der Benutzer eingeben wird verschwinden .

Verwandte Themen