ich wie dieser eine Inline-CSS haben für fokussierte Elemente (teilweise dargestellt)Javascript, CSS Änderung fokussiert Farbe für bestimmte Elemente
.InfoBox-body input[type=text]:focus,
.InfoBox-body input[type=password]:focus,
.InfoBox-body input[type=date]:focus,
.InfoBox-body input[type=datetime]:focus,
.InfoBox-body input[type=number]:focus,
.InfoBox-body input[type=search]:focus,
.InfoBox-body input[type=time]:focus,
.InfoBox-body input[type=url]:focus,
.InfoBox-body input[type=email]:focus,
.InfoBox-body select:focus{
-moz-box-shadow: 0 0 8px #88D5E9; /* this is sort of blue */
-webkit-box-shadow: 0 0 8px #88D5E9;
box-shadow: 0 0 8px #88D5E9;
border: 1px solid #88D5E9;
}
Jetzt implementiert ich einige Prüfungen vor (Loop Formularelemente) senden, und ich verwende :
element.focus();
in einer Schleife, wenn die Werte nicht mit dem erwarteten Inhalt übereinstimmen.
Dies funktioniert, indem ich das Problemelement fokussiere, aber jetzt möchte ich mehr ausgearbeitet :) Ändern der Fokusfarbe # 88D5E9 in rot.
habe ich versucht, diesen Ansatz
element.style.cssText = `
.InfoBox-body input[type=text]:focus,
.InfoBox-body input[type=password]:focus,
.InfoBox-body input[type=date]:focus,
.InfoBox-body input[type=datetime]:focus,
.InfoBox-body input[type=number]:focus,
.InfoBox-body input[type=search]:focus,
.InfoBox-body input[type=time]:focus,
.InfoBox-body input[type=url]:focus,
.InfoBox-body input[type=email]:focus,
.InfoBox-body select:focus{
-moz-box-shadow: 0 0 8px #FF0000;
-webkit-box-shadow: 0 0 8px #FF0000;
box-shadow: 0 0 8px #FF0000;
border: 1px solid #FF0000;
}
`;
aber nicht funktioniert.
Irgendwelche Hinweise? Vielen Dank.
Warum verwenden Sie cssText ... verwenden Sie einfach eine ungültige Klasse und haben Sie die CSS-Regel in Ihrem Stylesheet. – epascarello
können Sie bitte genauer sein :) – user1797147
'element.style.cssText' ist kein Ort, um CSS-Selektoren zu setzen - es ist ein Ort, um CSS ** -Regeln ** (das Bit zwischen den {}) –