Je suis en train de comprendre cette JS fonction: JS Fiddle Demodétecter la saisie de texte
Je fondamentalement, il est sorti d'un livre que je suis en train d'apprendre. Le livre s'appelle "JavaScript: le guide définitif" (pg484). Mais la fonction n'inclut pas le code html qui va avec. J'apprécierais que quelqu'un puisse m'aider à écrire le code HTML qui ferait ce travail, ainsi je pourrais être en mesure de mieux comprendre comment cela fonctionne. J'ai fait un coup de poignard à ce sujet avec le lien ci-dessus. Je n'aime vraiment pas ce livre comme il le fait. Cela arrive souvent. Je suis un novice, est-ce que quelqu'un a des conseils sur ce qu'il faut faire d'autre que de venir ici et d'essayer d'obtenir une réponse.
Appréciez toute aide.
//Example 17-7. Using the propertychange event to detect text input
function forceToUpperCase(element) {
if (typeof element === "string") element = document.getElementById(element);
element.oninput = upcase;
element.onpropertychange = upcaseOnPropertyChange;
// Easy case: the handler for the input event
function upcase(event) { this.value = this.value.toUpperCase(); }
// Hard case: the handler for the propertychange event
function upcaseOnPropertyChange(event) {
var e = event || window.event;
// If the value property changed
if (e.propertyName === "value") {
// Remove onpropertychange handler to avoid recursion
this.onpropertychange = null;
// Change the value to all uppercase
this.value = this.value.toUpperCase();
// And restore the original propertychange handler
this.onpropertychange = upcaseOnPropertyChange;
}
}
}
Veuillez prendre le temps de mettre en retrait votre code. Personne ne veut lire ce gâchis. Si tu veux notre aide, rends-la au moins aussi agréable que possible pour nous. – meagar
essayez http://jsfiddle.net/arunpjohny/vP9kD/1/ ou http://jsfiddle.net/arunpjohny/vP9kD/2/ –
Tks Arun, cela m'a été utile. – HattrickNZ