以下程序javascript部分第二句执行不过去,为什么???????
<!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>实验3.1</title>
<script type="text/javascript" src="test.js">
</script>
</head>
<body>
<form id="fruit">
<label><input type="radio" name="apple" value="2"/>
苹果(2元)</label>
<label><input type="radio" name="orange" value="3"/>
桔子(3元)</label>
<label><input type="radio" name="banana" value="4"/>
香蕉(4元)</label>
<label><input type="button" value="total cost" onclick="computeCost()"/>
</label>
<label>总计:<input type="text" name="cost"/></label>
</form>
</body>
</html>
javascript部分
function computeCost(){
var dom=document.getElementById("fruit");
dom.cost.value=dom.apple.value+dom.orange.value;
}javascriptinput
<!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>实验3.1</title>
<script type="text/javascript" src="test.js">
</script>
</head>
<body>
<form id="fruit">
<label><input type="radio" name="apple" value="2"/>
苹果(2元)</label>
<label><input type="radio" name="orange" value="3"/>
桔子(3元)</label>
<label><input type="radio" name="banana" value="4"/>
香蕉(4元)</label>
<label><input type="button" value="total cost" onclick="computeCost()"/>
</label>
<label>总计:<input type="text" name="cost"/></label>
</form>
</body>
</html>
javascript部分
function computeCost(){
var dom=document.getElementById("fruit");
dom.cost.value=dom.apple.value+dom.orange.value;
}javascriptinput
不明白你的意思
var dom=document.getElementById("fruit");
dom.cost.value=(+dom.apple.value)+(+dom.orange.value);
}