我想着重于使用JavaScript的输入元素。这是html。焦点()不工作在JavaScript或jQuery
<!DOCTYPE html>
<html>
<head>
<style>
input:focus {
background-color: yellow;
}
</style>
</head>
<body>
<p>Click inside the text fields to see a yellow background:</p>
<form>
First name: <input id="abc" type="text" name="firstname"><br>
</form>
</body>
</html>
当我手动点击使用鼠标,我可以看到黄色的背景。但是当我运行代码$('#abc')。focus()或document.getElementById('abc')。focus()我看不到黄色背景。如何使用JavaScript模拟鼠标焦点?
你的代码的工作,这里是[小提琴](https://开头的jsfiddle .net/kukicvladimir/1n5o4qkf /)我无法重现问题 –
代码正在工作,请尝试检查您是否在javascript中没有任何语法错误或为js文件命名空间路径 –
如果这是所有代码,那么就没有包括jQuery? – mrbubbles