js实现点击进行加减


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js从入门到放弃</title>
</head>
<body>
<input type="text" id="txt" value="1"/>
<input type="button" onclick="return add()" value="+" />
<input type="button" onclick="return jian()" value="-" />
<script type="text/javascript">
function add()
{
	var txt=document.getElementById('txt');
	var a=txt.value;
	if(a>=9)
    {
    	alert('对不起,库存件数不能大于等于9');
    }
    else
    {
    	a++;
    	txt.value=a;
    }
}
function jian()
{
	var txt=document.getElementById('txt');
	var b=txt.value;
	if(b<=1)
	{
		alert('对不起,库存件数不能为0');
	}
	else
	{
		b--;
		txt.value=b;
	}
}
</script>
</body>
</html>

展开阅读全文

没有更多推荐了,返回首页