<div class="htmlarea"> <textarea id="runcode57542"> <title>JavaScript控制文本框的值连续加减</title> <script language="javascript"> var flag1=0; var flag2=0; function NumberInc() { if(flag1==1 && flag2==1) {alert("Error!");} else { if(flag1==1) { document.all.TextBox1.value++; setTimeout("NumberInc()",100); } if(flag2==1) { document.all.TextBox1.value--; setTimeout("NumberInc()",100); } } } function md(obj) { if(obj.id=="Button1") flag1=1; if(obj.id=="Button2") flag2=1; NumberInc(); } function mo(obj) { if(obj.id=="Button1") flag1=0; if(obj.id=="Button2") flag2=0; } </script> <form runat="server"> <input id="TextBox1" runat="server" width="50" cssclass="mybutton" text="0"> <input type="button" id="Button1" value="+" onmousedown="md(this)" onmouseout="mo(this)" onmouseup="mo(this)"> <input type="button" id="Button2" value="-" onmousedown="md(this)" onmouseout="mo(this)" onmouseup="mo(this)"> </form> </textarea><br><input onclick="runEx('runcode57542')" type="button" value="运行代码"> <input onclick="doCopy('runcode57542')" type="button" value="复制代码"> <input onclick="doSave(runcode57542)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>