实例 触发选定元素的 blur 事件

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("input").focus();
    $("p").html("focus event triggered");
  });  
  $("#btn2").click(function(){
    $("input").blur();
    $("p").html("blur event triggered");
  }); 
});
</script>
</head>
<body>
Enter your name: <input type="text">
<br><br>
<button id="btn1">Trigger focus event</button>
<button id="btn2">Trigger blur event</button>
<p style="color:red">
</body>
</html>
                    

输出结果