Js Code:
Copy codeThe Code is as follows:
<Script language = "javascript">
// Global variable, which represents the number of file domains, and uses this variable to distinguish the name attribute of the file domain
Var file_count = 0;
// Add a file domain
Function additem (id ){
If (file_count> 9 ){
Alert ("up to u22810 u25991 u22495 ");
Return;
}
// Define the row variable, cell variable, and cell content variable, str.
Var row, cell, str;
// Insert a row into the table with the specified id
Row = eval ("document. all [" + '"' + id + '"' + "]"). insertRow ();
If (row! = Null ){
// Set the row background color
Row. bgColor = "white ";
// Insert a cell into the row
Cell = row. insertCell ();
// Set the str value, including a file domain 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 =" + '"' +" delete "+ '"' +" onclick = 'deleteitem (this, "+ '"' + "tb" + '"' +"); '> ";
// Increase the number of file Fields
File_count ++;
// Set innerHTML of a cell to str
Cell. innerHTML = str;
}
}
// Delete a file domain
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 codeThe Code is as follows:
<Input type = button value = "add" onclick = 'additem ("tb") '/> <br/>
<Table cellspacing = "0" id = "tb" style = "width: 400px">
</Table>