JavaScript implementation dynamic Increase in file domain forms _ form effects

Source: Internet
Author: User
Tags eval
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.