HTML
聚焦:element.focus()獲得焦點 element.blur()失去焦點 <input type="type" value="⇦ blur" onmouseout = "this.blur(); this.value= '⇦ blur'" onmouseover = "this.focus();this.value= '⇦ focus'" /> <style> input:focus {background-color: yellow } input {background-color: lime } </style>
<input type="type" value="⇦ blur" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").mouseover(function(){ $("input").focus(); $("input").val("focus"); }); $("input").mouseout(function() { $("input").blur(); $("input").val("blur"); }); }); </script>