首页 > 技术文章 > setInterval 实时驱动界面改变

Orange-C 2014-10-22 09:05 原文

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 2 <html xmlns="http://www.w3.org/1999/xhtml"> 
 3 <head> 
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
 5 <title>实时驱动界面改变</title> 
 6 <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> 
 7 </head> 
 8 <body> 
 9 输 入 值:<input type="text" id="inputValue" value="0" /> 
10 <br /> 
11 实时改变:<input type="text" id="inputChangeValue" value="0" /> 
12 </body> 
13 </html> 
14 <script type="text/javascript"> 
15 function setTxtValue() { 
16 var value = parseInt($("#inputValue").val()) 
17 $("#inputChangeValue").val(value) 
18 } 
19 var shTime; 
20 $(document).ready(function () { 
21 $("#inputValue").focus(function () { 
22 shTime = setInterval(setTxtValue, 100); 
23 }); 
24 $("#inputValue").blur(function () { 
25 clearInterval(shTime); 
26 }); 
27 }); 
28 </script> 

附件下载:https://files.cnblogs.com/Orange-C/demo.rar

推荐阅读