js 動態(tài)添加標簽(新增一行,其實很簡單,就是幾個函數(shù)的應用)
更新時間:2009年03月26日 01:56:24 作者:
把所有代碼拷下另存為一個html文件,在瀏覽器中打開,點擊“新增一行”按鈕就可以,以下是對js函數(shù)的解釋
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<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>
</head>
<body>
<div style="text-align: center" style="text-align: center">
<form>
<table width="90%">
<tr>
<td>
<BR />
<BR />
<h5>配置文件上傳</h5>
</td>
</tr>
<tr>
<td>
<table id="upload_file">
<tr class="tabletext">
<td><input type="file" name="job" size="50"/></td>
</tr>
<tr class="tabletext">
<td><input type="file" name='file2' size="50"/></td>
</tr>
<tr class="tabletext">
<td><input type="file" name='file3'size="50"/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left">
<input type="button" value="新增一行" onclick="add_one_file()"/>
<input type="submit" value="保 存"/>
<input name="ciname" value="{{ciname}}"/>
<input name="type" value="default"/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
把所有代碼拷下另存為一個html文件,在瀏覽器中打開,點擊“新增一行”按鈕就可以,以下是對js函數(shù)的解釋
document.createElement 創(chuàng)建一種頁面標簽
setAttribute:為某一標簽設置屬性
appendChild:在另一標簽中添加一子標簽
相關文章
js獲取對象,數(shù)組所有屬性鍵值(key)和對應值(value)的方法示例
這篇文章主要介紹了js獲取對象,數(shù)組所有屬性鍵值(key)和對應值(value)的方法,涉及javascript對于對象、數(shù)組鍵名與鍵值遍歷相關操作技巧,需要的朋友可以參考下2019-06-06js實現(xiàn)統(tǒng)計字符串中特定字符出現(xiàn)個數(shù)的方法
這篇文章主要介紹了js實現(xiàn)統(tǒng)計字符串中特定字符出現(xiàn)個數(shù)的方法,涉及javascript針對字符串中字符運算操作相關技巧,需要的朋友可以參考下2016-08-08解決AjaxFileupload 上傳時會出現(xiàn)連接重置的問題
這篇文章主要介紹了解決AjaxFileupload 上傳時會出現(xiàn)連接重置的問題,需要的朋友可以參考下2017-07-07一個簡單的JavaScript數(shù)據(jù)緩存系統(tǒng)實現(xiàn)代碼
數(shù)據(jù)緩存系統(tǒng),主要是將一些可復用的數(shù)據(jù)臨時存放一下,放下數(shù)據(jù)后面的再次調(diào)用。2010-10-10