javascript 在IE 和firefox 下的区别写了一段代码,在IE 下能正常运行,可是在firefox下就不能跑起来,下面是代码
<%-- extracted file comments /**filename: /common/securemessage/user/msgs_create.jsp
description: Send Secure Message screenincludes: /app/cs/user/includes/id_footer.jsp
/app/cs/user/includes/id_head.jsp
/app/cs/user/includes/id_table.jsp
/app/cs/user/includes/input_required_legend.jsp
/app/cs/user/includes/msg_form_block.jsp
/app/cs/user/includes/msg_sys_block.jsp
/app/cs/user/includes/nav_top_inside.jsp
/app/cs/user/includes/sys_block.jspnotes: None
branding: None
clearcase: #@# ACameron C:\\CPView\\cs_7x_src\\web\\common\\securemessage\\user\\msgs_create.jsp@@\\main\\Dev\\Dev_FWD-WAS-DB2\\5 Tue 06/24/2003 12:55p #$#
*/ --%><%-- load pg_bean --%><script language="JavaScript">
var row_index=0;
function addNewAttachFile(){
row_index++;
var contactTable = document.getElementById("attachFile");
var new_row=contactTable.insertRow(contactTable.rows.length);
new_row.setAttribute("id", "row"+row_index);
var new_col=new_row.insertCell(0);
new_col.innerHTML='<td class="input"><input type ="file" name="file[' +(row_index)+ '] size="50"/></td>';
var new_col=new_row.insertCell(1);
new_col.innerHTML='<td class="input"><input type="button" value="Delete" onclick=removeFile(attachFile,this)></td>';
}function removeFile(table,objTD){
var objTR=objTD.parentElement.parentElement;
currRowIndex=objTR.rowIndex;
table.deleteRow(currRowIndex);
}
</script><html:form action="/common/securemessage/user/create"
enctype="multipart/form-data" method="post">
<tr bgcolor="#ffffff">
<td class="wtspace"> </td>
<td class="label"> </td>
<td class="input"> </td>
<td class="wtspace"> </td>
</tr>
<tr bgcolor="#ffffff">
<td class="wtspace"> </td>
<td class="labeltop"><tiles:getAsString name="attachfile" />: </td>
<td class="input">
<table id="attachFile">
<tr>
<td><input type="file" name="file[0]" size="50" /> </td>
<td class="labeltop"><a href="#" target="_self"
class="PrimaryButton" onclick="javascript:addNewAttachFile()">
<span><tiles:getAsString name="addNewFile" /></span></a></td>
</tr>
</table>
</td>
<td class="wtspace"> </td>
</tr>
<tr bgcolor="#ffffff">
<td class="wtspace"> </td>
<td class="label"> </td>
<td class="input"> </td>
<td class="wtspace"> </td>
</tr>
这段代码就是实现多文件上传,在初始化这个页面后,会有一行显示一个文件上传框,当用户点add new file按钮的时候,会增加一行,让用户再上传一个文件。
这个功能在IE 下面能正常使用,可是在firefox 下面新增加的文件上传不能够被识别,它只能够识别最初的那个文件,也即只有第一个文件能被识别,后面用JS 增加的上传文件都不能够被识别哪位大侠帮个忙解决一下!
<%-- extracted file comments /**filename: /common/securemessage/user/msgs_create.jsp
description: Send Secure Message screenincludes: /app/cs/user/includes/id_footer.jsp
/app/cs/user/includes/id_head.jsp
/app/cs/user/includes/id_table.jsp
/app/cs/user/includes/input_required_legend.jsp
/app/cs/user/includes/msg_form_block.jsp
/app/cs/user/includes/msg_sys_block.jsp
/app/cs/user/includes/nav_top_inside.jsp
/app/cs/user/includes/sys_block.jspnotes: None
branding: None
clearcase: #@# ACameron C:\\CPView\\cs_7x_src\\web\\common\\securemessage\\user\\msgs_create.jsp@@\\main\\Dev\\Dev_FWD-WAS-DB2\\5 Tue 06/24/2003 12:55p #$#
*/ --%><%-- load pg_bean --%><script language="JavaScript">
var row_index=0;
function addNewAttachFile(){
row_index++;
var contactTable = document.getElementById("attachFile");
var new_row=contactTable.insertRow(contactTable.rows.length);
new_row.setAttribute("id", "row"+row_index);
var new_col=new_row.insertCell(0);
new_col.innerHTML='<td class="input"><input type ="file" name="file[' +(row_index)+ '] size="50"/></td>';
var new_col=new_row.insertCell(1);
new_col.innerHTML='<td class="input"><input type="button" value="Delete" onclick=removeFile(attachFile,this)></td>';
}function removeFile(table,objTD){
var objTR=objTD.parentElement.parentElement;
currRowIndex=objTR.rowIndex;
table.deleteRow(currRowIndex);
}
</script><html:form action="/common/securemessage/user/create"
enctype="multipart/form-data" method="post">
<tr bgcolor="#ffffff">
<td class="wtspace"> </td>
<td class="label"> </td>
<td class="input"> </td>
<td class="wtspace"> </td>
</tr>
<tr bgcolor="#ffffff">
<td class="wtspace"> </td>
<td class="labeltop"><tiles:getAsString name="attachfile" />: </td>
<td class="input">
<table id="attachFile">
<tr>
<td><input type="file" name="file[0]" size="50" /> </td>
<td class="labeltop"><a href="#" target="_self"
class="PrimaryButton" onclick="javascript:addNewAttachFile()">
<span><tiles:getAsString name="addNewFile" /></span></a></td>
</tr>
</table>
</td>
<td class="wtspace"> </td>
</tr>
<tr bgcolor="#ffffff">
<td class="wtspace"> </td>
<td class="label"> </td>
<td class="input"> </td>
<td class="wtspace"> </td>
</tr>
这段代码就是实现多文件上传,在初始化这个页面后,会有一行显示一个文件上传框,当用户点add new file按钮的时候,会增加一行,让用户再上传一个文件。
这个功能在IE 下面能正常使用,可是在firefox 下面新增加的文件上传不能够被识别,它只能够识别最初的那个文件,也即只有第一个文件能被识别,后面用JS 增加的上传文件都不能够被识别哪位大侠帮个忙解决一下!
但是就是上传的文件程序 读不出来
只能读出最初始的即第一行的那个文件
通过add new file 增加的文件不能够被增加进去
function removeFile(table,objTD){
//var objTR=objTD.parentElement.parentElement;
//FF不要使用parentElement对象,不支持这个对象,而是使用parentNode,IE和ff都支持
var objTR=objTD.parentv.parentNode;
currRowIndex=objTR.rowIndex;
table.deleteRow(currRowIndex);
}
在代码程序里面,不能用而且我的主要功能是实现多文件上传,但是用这个JS 在IE 下面能够 实现
在FF 下面,就不能够实现多文件上传,只能上传一个文件所以想知道在FF 下的这个JS 应该怎么改一下
//var objTR=objTD.parentElement.parentElement;
//FF不要使用parentElement对象,不支持这个对象,而是使用parentNode,IE和ff都支持
//var objTR=objTD.parentv.parentNode;
var objTR=objTD.parentNode.parentNode;//改成这样才行 currRowIndex=objTR.rowIndex;
table.deleteRow(currRowIndex);
}
可能在insertRow、insertCell不兼容吧,用createElementvar new_col=new_row.insertCell(0);
new_col.innerHTML='<td class="input"><input type ="file" name="file[' +(row_index)+ '] size="50"/></td>';
var new_col=new_row.insertCell(1);
new_col这个定义了2次<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title></title>
</head>
<script language="javascript">
function chick(){
var _count = document.getElementById("files").getElementsByTagName("input");
var len = _count.length - 1;
var _obj = _count[len];
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
if (ie) {
_obj.click();
}
else {
var a = document.createEvent("MouseEvents");
a.initEvent("click", true, true);
_obj.dispatchEvent(a);
}
var _path = _obj.value;
alert("得到路径:" + _path);
var _parent = document.getElementById("path_table").firstChild;
var row = document.createElement("tr");
row.setAttribute("id",len);
var cell1 = document.createElement("td");
cell1.style.borderBottom = "solid";
cell1.style.borderBottomWidth = "1px";
var cell2 = document.createElement("td");
cell2.style.borderBottom = "solid";
cell2.style.borderBottomWidth = "1px";
var _a = document.createElement("a");
_a.innerHTML = "取消";
_a.href = "javascript:remove("+len+")";
var _text = document.createTextNode(_path);
cell1.appendChild(_text);
cell2.appendChild(_a);
row.appendChild(cell1);
row.appendChild(cell2);
_parent.appendChild(row);
}
function create(){
//统计现有input
var length = document.getElementById("files").getElementsByTagName("input").length;
var _id = "";
if (length == 0) {
_id = "0"
} else {
_id = length;
}
//添加一个新的INPUT
var _td = document.getElementById("input_td");
var _input = document.createElement("input");
_input.setAttribute("type", "file");
_input.setAttribute("name", "pics[]");
//alert(_input.getAttribute('name'));
_input.setAttribute("id", _id);
_td.appendChild(_input);
chick();
}
function remove(obj) {
var _rem = document.getElementById(obj);
var _remt = document.getElementById("path_table").firstChild;
_remt.removeChild(_rem);
var _inputs = document.getElementById("files").getElementsByTagName("input");
for (var i = 0; i < _inputs.length; i++) {
var tmp = _inputs[i];
aler
if (tmp.getAttribute("id") == obj) {
document.getElementById("input_td").removeChild(tmp);
break;
}
}
}
function submitForm() {
alert("提交 form表单");
var _inputs = document.getElementById("files").getElementsByTagName("input");
for (var i = 0; i < _inputs.length; i++) {
var tmp = _inputs[i];
alert("已选择文件:" + tmp.value);
}
document.fileupload.submit();
}
</script>
<body bgcolor="white">
<form name="fileupload" method="post" action="uploadservlet.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="600">
<tr>
<td>
文件上传
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0"
width="100%" id="path_table" style="border-bottom:solid; border-bottom-width:1px;">
<tr id="first_tr">
<td width="80%" style="border-bottom:solid; border-bottom-width:1px;">
文件路径
</td>
<td width="20%" style="border-bottom:solid; border-bottom-width:1px;">
操作
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input name="button" type="button" onclick="create();" value="选择文件" />
<input type="submit" value="提交" onclick="submitForm()"/>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" id="files" style="display:none;">
<tr>
<td id="input_td">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
多文件上传
function addNewAttachFile(){
row_index++;
var contactTable = document.getElementById("attachFile");
var new_row=contactTable.insertRow(contactTable.rows.length);
new_row.setAttribute("id", "row"+row_index);
var new_col=new_row.insertCell(0);
new_col.className=='input';
//td的内容又添加了td,⊙﹏⊙b汗,把td删掉 new_col.innerHTML='<input type ="file" name="file[' +(row_index)+ '] size="50"/>';
new_col=new_row.insertCell(1);
new_col.className=='input';
new_col.innerHTML='<input type="button" value="Delete" onclick=removeFile(document.getElementById(\'attachFile\'),this)>';
}function removeFile(table,objTD){
var objTR=objTD.parentNode.parentNode; currRowIndex=objTR.rowIndex; table.deleteRow(currRowIndex);
}
这样firefox里的问题就好了这个问题解决了