js 動態(tài)添加標(biāo)簽(新增一行,其實(shí)很簡單,就是幾個函數(shù)的應(yīng)用)
更新時間:2009年03月26日 01:56:24 作者:
把所有代碼拷下另存為一個html文件,在瀏覽器中打開,點(diǎn)擊“新增一行”按鈕就可以,以下是對js函數(shù)的解釋
復(fù)制代碼 代碼如下:
<!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文件,在瀏覽器中打開,點(diǎn)擊“新增一行”按鈕就可以,以下是對js函數(shù)的解釋
document.createElement 創(chuàng)建一種頁面標(biāo)簽
setAttribute:為某一標(biāo)簽設(shè)置屬性
appendChild:在另一標(biāo)簽中添加一子標(biāo)簽
相關(guān)文章
js獲取對象,數(shù)組所有屬性鍵值(key)和對應(yīng)值(value)的方法示例
這篇文章主要介紹了js獲取對象,數(shù)組所有屬性鍵值(key)和對應(yīng)值(value)的方法,涉及javascript對于對象、數(shù)組鍵名與鍵值遍歷相關(guān)操作技巧,需要的朋友可以參考下2019-06-06JS實(shí)現(xiàn)可點(diǎn)擊展開與關(guān)閉的左側(cè)廣告代碼
這篇文章主要介紹了JS實(shí)現(xiàn)可點(diǎn)擊展開與關(guān)閉的左側(cè)廣告代碼,通過鼠標(biāo)onClick事件調(diào)用自定義javascript函數(shù)實(shí)現(xiàn)頁面元素及樣式的顯示與隱藏效果,非常簡單實(shí)用,需要的朋友可以參考下2015-09-09js實(shí)現(xiàn)統(tǒng)計(jì)字符串中特定字符出現(xiàn)個數(shù)的方法
這篇文章主要介紹了js實(shí)現(xiàn)統(tǒng)計(jì)字符串中特定字符出現(xiàn)個數(shù)的方法,涉及javascript針對字符串中字符運(yùn)算操作相關(guān)技巧,需要的朋友可以參考下2016-08-08解決AjaxFileupload 上傳時會出現(xiàn)連接重置的問題
這篇文章主要介紹了解決AjaxFileupload 上傳時會出現(xiàn)連接重置的問題,需要的朋友可以參考下2017-07-07一個簡單的JavaScript數(shù)據(jù)緩存系統(tǒng)實(shí)現(xiàn)代碼
數(shù)據(jù)緩存系統(tǒng),主要是將一些可復(fù)用的數(shù)據(jù)臨時存放一下,放下數(shù)據(jù)后面的再次調(diào)用。2010-10-10微信小程序如何在頁面跳轉(zhuǎn)時進(jìn)行頁面導(dǎo)航
小程序能夠在不同的頁面進(jìn)行跳轉(zhuǎn)切換,路由起到了至關(guān)重要的作用,下面這篇文章主要給大家介紹了關(guān)于微信小程序如何在頁面跳轉(zhuǎn)時進(jìn)行頁面導(dǎo)航的相關(guān)資料,需要的朋友可以參考下2022-09-09