When you run this code and press input2 , it will get focus, and the .result div will output "f2" once. But when you press input1 , the script will allow input2 to get focus, and the .result div will output "f2" twice, why?
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>blank</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $(".input1").click(function(){$(".input2").focus();}); $(".input2").focus(function(){$(".result").html($(".result").html()+"f2, ");}); }); </script> </head> <body> <p> <input class="input1" value="click me to set the input2 focus" /> <input class="input2" value="input2" /> <div class="result"></div> </p> </body> </html>
csdxf source share