我正在寻找一种方法,如果页面的任何输入处于焦点状态,则不执行函数(e)。 尝试了好几种方法都没有成功;(
这是我的代码:
document.onkeyup=function(e){
var e = e || window.event;//Pour IE
// Action sur la barre d'espace (32)
if(e.which == 32) {
$("#play").click();
return false;
}
//Action sur entrée (13)
if(e.which == 13) {
$("#play").click();
return false;
}
}
我尝试过这样的事情
if ($('input').is(":focus")) {
}
else{ my code }
但是这不起作用。
谢谢你帮助我!
艾蒂安
最佳答案
javascript 中的 onfocus 事件
<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" onfocus="myFunction(this)">
<p>When the input field gets focus, a function is triggered which changes the background-color.</p>
<script>
function myFunction(x) {
x.style.background = "yellow";
}
</script>
</body>
</html>
关于javascript - 如果有任何输入获得焦点,则不执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49148899/