Habt Ihr irgendwelche hilfreiche Tipps für mich?
var inp=document.getElementsByTagName('input');
for (var i in inp) {
try {
if (inp[i].type == "password") {
inp[i].setAttribute("was_password", inp[i].style.backgroundColor + ":" + inp[i].style.color);
inp[i].type= "text";
inp[i].style.backgroundColor= "red";
inp[i].style.color= "yellow";
}
else if (inp[i].getAttribute("was_password") != null) {
inp[i].type="password";
var old= inp[i].getAttribute("was_password").split(":");
inp[i].style.backgroundColor= old[0];
inp[i].style.color= old[1];
inp[i].removeAttribute("was_password");
}
}
catch (e) {}
}
void(0);
Ich hab mal deinen aktuellen Post hier gepostet, damit nich jeder auf die Seite gehen muss, nach deinem Script suchen muss nur um zu sehen worauf ich mich beziehe.
Was IMO unschön ist, ist, dass immer alle Passwort-Felder umgeschalten werden, das du invalide Attribute benutzt und inline-style-Angaben.
Da dachte ich mir ein Button neben jedem togglebarem Passwort-Feld der nur für das eine Feld funktioniert wäre besser, statt ein invalides Attribut zu benutzen um sich die alten inline-style-Angaben zu merken, sie sich einfach gar nicht merken und statt inline-styles einfach ein style-Element & eine Klasse zu benutzen:
// creates and attaches a new style element (inline styles are crap!)
var style = document.createElement("style");
style.innerText = "input.pwd-visible { \n\tbackground-color: #f00 !important;\n\tcolor: #ff0 !important;\n }";
document.getElementsByTagName("head")[0].appendChild(style);
// this is the event handler for the buttons
var event_handler = function() {
var was_pwd_before = this.related_input.type === "password";
this.related_input.type = was_pwd_before ? "text" : "password";
this.innerText = was_pwd_before ? "hide" : "show";
this.related_input.classList.toggle("pwd-visible");
};
// creation of the buttons for each password typed input element
var list = document.querySelectorAll("input[type=password]");
for(var i = 0; i < list.length; i++) {
// create new button element
var btn = document.createElement("button");
btn.type = "button";
btn.innerHTML = "show";
btn.addEventListener("click", event_handler);
// attach the input field as buttons property and insert the button behind the input field
var input = list[i];
btn.related_input = input;
input.parentNode.insertBefore(btn, input.nextSibling);
}
MfG
bubble
--
If "god" had intended us to drink beer, he would have given us stomachs. - David Daye
If "god" had intended us to drink beer, he would have given us stomachs. - David Daye