JS Code:
Copy Code code as follows:
<script language= "JavaScript" >
Global variables, which represent the number of file fields and use this variable to distinguish the Name property of the file field
var file_count = 0;
adding file fields
function additem (ID) {
if (File_count > 9) {
Alert ("Most u22810 10 u25991 pieces u22495");
Return
}
defines row variables rows; cell variables cell; content variable str.
var row,cell,str;
Inserts a row in the table with the specified ID
row = eval ("document.all[" + ' "' +id+ '" ' + "]"). InsertRow ();
if (row!= null) {
Set the background color of a row
row.bgcolor= "White";
Insert cells in a row
Cell = Row.insertcell ();
Set the value of STR, including a file field and a Delete button
Str= ' <input onselectstart= "return false" class= "TF" onpaste= "return false" type= "file" name= "file[' + File_count + ']" Style= "width:500px" onkeydown= "return false;" /> ';
str = "<input type=" + "" + "button" + "" ' + "value=" + "" ' + "remove" + "" ' + "onclick= ' DeleteItem (this," + "" ' + "TB" + ' "" + "); ' > ";
Increased number of file domains
file_count++;
Set the cell's innerHTML to the contents of STR
CELL.INNERHTML=STR;
}
}
Delete a file field
function DeleteItem (obj,id) {
var Rownum,currow;
Currow = Obj.parentNode.parentNode;
RowNum = eval ("document.all." +id). rows.length-1;
Eval ("document.all[" + ' "' +id+ '" ' + "]"). DeleteRow (Currow.rowindex);
file_count--;
}
</script>
HTML code:
Copy Code code as follows:
<input Type=button value= "Add" onclick= ' AddItem ("TB") '/><br/>
<table cellspacing= "0" id= "TB" style= "width:400px" >
</table>