<!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>
</head>
<script language="javascript">
function js(){
var jj=document.getElementById("整机价格");
document.getElementById("首付款").value()=jj*0.3 //如何整 。。
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
整机价:
<input type="text" name="整机价格" id="整机价格" onkeyup="javascript: js()" />
</p>
<p>
首付款:
<input type="text" name="首付款" id="首付款" />
</p>
<p>
保险费:
<input type="text" name="保险费" id="保险费" />
</p>
<p>运 费:
<input type="text" name="运费" id="运费" />
</p>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function js(){
var jj=document.getElementById("整机价格");
document.getElementById("首付款").value()=jj*0.3 //如何整 。。
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
整机价:
<input type="text" name="整机价格" id="整机价格" onkeyup="javascript: js()" />
</p>
<p>
首付款:
<input type="text" name="首付款" id="首付款" />
</p>
<p>
保险费:
<input type="text" name="保险费" id="保险费" />
</p>
<p>运 费:
<input type="text" name="运费" id="运费" />
</p>
</form>
</body>
</html>
var jj = +document.getElementById("整机价格").value;
document.getElementById("首付款").value = jj * 0.3 //如何整 。。
}
id最好别用中文
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function js() {
//获取整机价格
var jj = document.getElementById("整机价格").value;
//获取整机价格乘以0.3的值
var jiage = jj * 0.3;
//把值赋给首付款
document.getElementById("首付款").value = jiage; //如何整 。。
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
整机价:
<input type="text" name="整机价格" id="整机价格" onblur="js()" />
</p>
<p>
首付款:
<input type="text" name="首付款" id="首付款" value="" />
</p>
<p>
保险费:
<input type="text" name="保险费" id="保险费" />
</p>
<p>
运 费:
<input type="text" name="运费" id="运费" />
</p>
</form>
</body>
</html>
var jj=document.getElementById("整机价格");这句拿不到东西吧
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function js(){
var patrn = /^[0-9]*[1-9][0-9]*$/;
var jj=document.getElementById("整机价格").value;
//value是属性不是方法,没有()
//还有就是1楼说的,id尽量用有意义的英文
//先判断输入的是否是数字
if(!patrn.exec(jj)){
alert("请输入数字");
return;
}else{
document.getElementById("首付款").value=parseInt(jj)*0.3
}
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
整机价:
<input type="text" name="整机价格" id="整机价格" onkeyup="js()" />
</p>
<p>
首付款:
<input type="text" name="首付款" id="首付款" />
</p>
<p>
保险费:
<input type="text" name="保险费" id="保险费" />
</p>
<p>运 费:
<input type="text" name="运费" id="运费" />
</p>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style>
input {text-align:right}
</style>
<script language="javascript">
function js(obj){ //参数为input对象
var reg = /^[\d]*\.?(\d{1,2})?$/; //匹配可包含小数点和两位小数的数字
if (!reg.test(obj.value)) { //若不符合规格
alert("请输入合法金额");
obj.value = obj.value.substring(0,obj.value.length-1); //去除最后输入的一个字符
obj.focus();
}
else {
if (obj.value == "") document.getElementById("first").value = ""; //若删除了整机价,清空首付款
else document.getElementById("first").value = (parseFloat(obj.value)*0.3).toFixed(2); //toFixed(2):取2位小数
}
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
整机价:
<input type="text" name="whole" id="whole" onkeyup="js(this)" onblur="this.value=parseFloat(this.value).toFixed(2)"/>
</p>
<p>
首付款:
<input type="text" name="first" id="first" />
</p>
<p>
保险费:
<input type="text" name="safety" id="safety" />
</p>
<p>运 费:
<input type="text" name="trans" id="trans" />
</p>
</form>
</body>
</html>