为何这个jsp文件中不能调用js呢?

来源:百度知道 编辑:UC知道 时间:2024/06/30 23:48:32
<html>
<head>
<title>test</title>
<script language="javascript">
function test(){
var str= document.form1.Mamount0.value+ document.form1.tel.value;
document.form1.tel2.value = str;
}
</script>
</head>

<body>
<form name="form1">
<table>
<%for(int i=1;i<5;i++){%>
<tr> <input type="hidden" name="Mamount0" id="Mamount0" value="55"></tr>
<tr><input type="text" name="tel" onKeyUp="test()"/></tr>
<tr><input type="text" name="tel2"/></tr>
<%}%>
<table>
</form>
</body>
</html>

但是用一下这个又行:
<html>
<head>
<title>test</title>
<script language="javascript"><

<%for(int i=1;i<5;i++){%>
<tr> <input type="hidden" name="Mamount0" id="Mamount0" value="55"></tr>
<tr><input type="text" name="tel" onKeyUp="test()"/></tr>
<tr><input type="text" name="tel2"/></tr>
<%}%>

就是这个有问题!
没循环1次就有1次这样的 东西!循环4次就有4个!你每次循环的时候 name="tel"的就有4个!你这样做叫JS脚本到底用哪个呢???

这里得到将会是一个数组,因为name一样。