JS dynamic tagging (add a line, in fact very simple, is the application of several functions) _javascript skills

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>add_line</title>
<script language= "javascript" type= "Text/jscript" ><!--

function Add_input_file (tbfile, index)
{
file_name = "file" + index;
var tr_file = document.createelement ("tr");
var td_file = document.createelement ("TD");
var input_file = document.createelement ("input")
Input_file.setattribute ("type", "File")
Input_file.setattribute ("Size", "50")
Input_file.setattribute ("name", file_name)

Td_file.appendchild (Input_file)
Tr_file.appendchild (Td_file)
Tbfile.appendchild (Tr_file)
}
function Add_one_file ()
{
var tb_file = document.getElementById ("Upload_file");
var count_file = document.getElementById ("Upload_file"). Childnodes.length;
Window.alert (steps_nums);
Add_input_file (Tb_file, count_file);
}

--></script>
<body>
<div style= "Text-align:center" style= "Text-align:center" >
<form>
<table width= "90%" >
<tr>
<td>
<br/>
<br/>
</td>
</tr>
<tr>
<td>
<table id= "Upload_file" >
<tr class= "Tabletext" >
<td><input type= "file" name= "job" size= "/></td>"
</tr>
<tr class= "Tabletext" >
<td><input type= "file" Name= ' file2 ' size= "/></td>"
</tr>
<tr class= "Tabletext" >
<td><input type= "file" Name= ' File3 ' size= "/></td>"
</tr>
</table>
</td>
</tr>

<tr>
&LT;TD align= "Left" >
<input type= "button" value= "New Row" onclick= "Add_one_file ()"/>
<input type= "Submit" value= "Save"/>
<input name= "Ciname" value= "{Ciname}}"/>
<input name= "type" value= "Default"/>
</td>
</tr>
</table>
</form>
</div>
</body>

Put all the code under the Save as an HTML file, open in the browser, click the "New Line" button can be, the following is the JS function explanation

Document.createelement Create a page label
SetAttribute: Set properties for a label
AppendChild: Add a child label to another label

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.