JavaScript控制文本框的值加减
<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>
<html>
<body>
<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>
</body>
</html>
本文作者:未知