Hallo zusammen,
mit dem folgenden Code möchte ich herne prüfen, ob das Input-Feld im Focus steht:
Aber ich erhalte keine Ausgabe - was mache ich hier falsch?
VG, David
mit dem folgenden Code möchte ich herne prüfen, ob das Input-Feld im Focus steht:
HTML-Code:
<html> <head> </head> <body> <div class="form-group"> <label for="usr">Name:</label> <input type="text" style="width:20%; margin:auto;" class="form-control" id="usr"> </div> <p id="demo"></p> <script> setInterval("myFunction()", 1); function myFunction() { var x = document.getElementById("demo"); var y = document.getElementById("usr"); if (y.hasFocus()) { x.innerHTML = "The document has focus."; } else { x.innerHTML = "The document DOES NOT have focus."; } } </script> </body> </html>
VG, David
Kommentar