Frage

Ich habe ein Eingabebox, das den Standardwert "Schlüsselwörter eingeben".Ich habe auch zwei andere Kontrollkästchen, sodass Benutzer Kontrollkästchen entweder auswählen und suchen oder ein Schlüsselwort eingeben oder suchen oder beide tun.Nur für den Fall, dass sie nur auswählen, Kontrollkästchen, ich möchte erkennen, ob sich in der Eingabebox nichts geändert hat, und den Wert leer einstellen.Wie mache ich das in jquery? generasacodicetagpre.

so etwas ??? generasacodicetagpre.

versuchte dies: funktioniert nicht .. generasacodicetagpre.

War es hilfreich?

Lösung

It sounds like you're trying to do a watermark. Depending on your browser support requirements, you may want to take a look at the placeholder attribute. Allows for a nice watermark without actually changing the text box's value. (There are numerous jQuery plugins that accomplish the same thing in a cross browser manner. )

<input type="text" placeholder="Enter Keywords" /> 

Andere Tipps

Instead of using indexOf you can do direct comparison.

    var keywords = encodeURIComponent($(".BasicSearchInputBox").val()); 

    if (keywords == "Enter Keywords")
    {
        window.location.href = url + '&k=' + checkboxValues;
    }
    else{               
        window.location.href = url + '&k=' + keywords + checkboxValues;
    }

Something like:

function defaultTxt(obj) {
    var txt=obj.val();
    obj.focus(function(){
        if(obj.val()==txt) {obj.val('');}
    }).blur(function(){
        if(!obj.val()) {obj.val(txt);}
    });
}

Then call assign it through a loop:

// Array or elements
var elems=['input'];
$(elems).each(function(){
    defaultTxt($(this));
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top