onclick问题
<%@ page language= "java " contentType= "text/html; charset=gbk "
pageEncoding= "gbk "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gbk ">
<title> Insert title here </title>
<script type= "text/javascript ">
var index=1
function addfile(){
alert( "a ")
var div=document.getElementById( "div1 ")
var file=document.createElement( "input ")
file.setAttribute( "type ", "file ")
var name=file+index
file.setAttribute( "name ",name)
div.appendChild(file)
var br=document.createElement( "br ")
div.appendChild(br)
}
</script>
</head>
<body>
<form action= "servlet/test " method= "post ">
<table align= "center ">
<tr>
<td> To: <br>
<input type= "text " name= "to " size=25> </td>
<td> From: <br>
<input type= "text " name= "from " size=25> </td>
</tr>
<tr>
<td colspan= "2 ">
Subject: <br>
<input type= "text " name= "subject " size=50>
</td>
</tr>
<tr>
<td colspan= "2 ">
File: <br>
<input type= "button " name= "addfile " value= "增加附件 " onclick= "addfile() ">
<div id= "div1 "> <input type= "file " name= "file1 " size=50 maxlength=50> </div>
</td>
</tr>
<tr>
<td colspan= "2 ">
<p> Message: <br>
<textarea name= "content " rows=25 cols=85> </textarea> </p>
</td>
</tr>
<tr>
<td colspan= "2 ">
<input type= "submit " value= "send "> <input type= "reset " value= "clear ">
</td>
</tr>
</table>
</form>
</body>
</html>
---------------------------------------
代码如上,name为addfile的button中的onclick= "addfile() "没有反映
如果去掉 <form .....> 和 </form> 则正常
如果把onclick改为onclick= "alert( 'a ') "能弹出
改成addfile()就是没放映
------解决方案--------------------把你调用addfile()那个地方的button的name换个名字,不要也取作addfile看看