<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
function res() {
document.all.num.value=document.all.num.value*document.all.price.value;}
</script>
</head> <body>
<form name="myform">
<input type="text" value="1" name="num" onblur="res()">
<input type="text" value="1" name="price">
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
function res() {
document.all.num.value=document.all.num.value*document.all.price.value;}
</script>
</head> <body>
<form name="myform">
<input type="text" value="1" name="num" onblur="res()">
<input type="text" value="1" name="price">
</form>
</body>
</html>
function price()
{
var num=document.myform.num.value;
var price=document.myform.price.value;
var last=parseInt(num)*parseInt(price);
document.myform.price.value=last;
}
</script> 通过document.myform.price.value取得的值应该是string类型,要进行数学计算先要转换。
这个文本框里只能输入正整数 不出现0和小数点???