有谁知道为什么在以下focus()
事件处理程序中显示一个简单的警告框永远不会停止?我也试过focusin()
同样的结果。事件是否在循环中多次触发? 我在Chrome中运行
$('input[type=text]').focus(function() { // Also tried focusin(..)
alert('Focus');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Input:
<input type="text" id="myinput"/>
答案 0 :(得分:1)
$('input[type=text]').focus(function() { // Also tried focusin(..)
alert('focus');
$(this).blur();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Input:
<input type="text" id="myinput"/>
另外:Javascript: cross browser solution for selecting all text inside a textbox on focus