<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<title>RunJS 演示代码</title>
<style>
.* {
padding: 0
margin: 0
}
a {
text-decoration: none
color: black
}
a:hover {
color: red
}
.wrap {
width: 900px
height: 300px
overflow-y: auto
margin: auto
}
table {
width: 800px
border: 1px solid black
border-collapse: collapse
}
th {
background-color: orange
}
td,th {
border: 1px solid black
text-align: center
}
table input[type=text] {
width: 100px
}
</style>
<script>
var yugi = {
col: 6,
addRow: function(table) {
var vals = [a.value, b.value, c.value, d.value, e.value, "<a href='###' onclick='yugi.modify(table,this)'>修改</a>&nbsp<a href='###' onclick='yugi.del(table,this)'>删除</a>"]
var tr = table.insertRow(table.tBodies[0].rows.length)
for (var i = 0 i < yugi.col i++) {
var td = tr.insertCell(tr.cells.length)
td.innerHTML = vals[i]
}
},
modify: function(table, row) {
var r = row.parentElement.parentElement,
c = r.cells
if (/.*修改.*/g.test(row.innerHTML)) {
for (var i = 0 i < c.length - 1 i++) {
var ci = c[i]
var txt = document.createElement("input")
txt.type = "text"
txt.value = ci.innerHTML
ci.innerHTML = ""
ci.appendChild(txt)
}
row.innerHTML = "保存"
} else {
for (var i = 0 i < c.length - 1 i++) {
var ci = c[i]
ci.innerHTML = ci.children[0].value
}
row.innerHTML = "修改"
}
},
del: function(table, row) {
var ind = row.parentElement.parentElement.rowIndex
table.tBodies[0].deleteRow(ind)
}
}
</script>
</head>
<body>
<fieldset class="wrap">
<legend>学生信息列表</legend>
<div>
<input type="text" id="a" />
<input type="text" id="b" />
<input type="text" id="c" />
<input type="text" id="d" />
<input type="text" id="e" />
<input type="button" value="添加" onclick="yugi.addRow(table)" />
</div>
<table id="table">
<tr>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
<th>学历</th>
<th>性别</th>
<th>地址</th>
</tr>
</table>
</fieldset>
</body>
</html>
本文为大家介绍下使用js及jquery实现动态的文件上传 *** 作按钮的添加和删除,具体示例如下,希望对大家有所帮助javascript实现
代码如下:
<!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>
<meta
http-equiv="Content-Type"
content="text/html
charset=utf-8"
/>
<title>jquery文件上传</title>
<script
type="text/javascript"
src="jquery-1.7.2.js"></script>
<script
type="text/javascript">
var
addMore
=
function()
{
var
div
=
document.getElementById("div2")
var
br
=
document.createElement("br")
var
input
=
document.createElement("input")
var
button
=
document.createElement("input")
input.setAttribute("type",
"file")
button.setAttribute("type",
"button")
button.setAttribute("value",
"Remove")
button.onclick
=
function()
{
div.removeChild(br)
div.removeChild(input)
div.removeChild(button)
}
div.appendChild(br)
div.appendChild(input)
div.appendChild(button)
}
//节点的移动
//$(function(){
//})
</script>
</head>
<body>
<div
id="div1">
<input
type="file"
id="upload"/>
<input
type="button"
id="btn"
value="more"
onclick="addMore()"/>
</div>
<div
id="div2"></div>
</body>
</html>
jquery实现
代码如下:
<!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>
<meta
http-equiv="Content-Type"
content="text/html
charset=utf-8"
/>
<title>jquery文件上传</title>
<title>jquery1</title>
<script
type="text/javascript"
src="jquery-1.7.2.js"></script>
<script
type="text/javascript">
/**
var
addMore
=
function()
{
var
div
=
document.getElementById("div2")
var
br
=
document.createElement("br")
var
input
=
document.createElement("input")
var
button
=
document.createElement("input")
input.setAttribute("type",
"file")
button.setAttribute("type",
"button")
button.setAttribute("value",
"Remove")
button.onclick
=
function()
{
div.removeChild(br)
div.removeChild(input)
div.removeChild(button)
}
div.appendChild(br)
div.appendChild(input)
div.appendChild(button)
}**/
//jquery实现文件上传的按钮添加和删除
$(function(){
$("input[type=button]").click(function(){
var
br
=
$("<br>")
var
input
=
$("<input
type='file'/>")
var
button
=
$("<input
type='button'
value='Remove'/>")
$("#div1").append(br).append(input).append(button)
button.click(function()
{
br.remove()
input.remove()
button.remove()
})
})
})
</script>
</head>
<body>
<div
id="div1">
<input
type="file"
id="upload"/>
<input
type="button"
id="btn"
value="more"
onclick="addMore()"/>
</div>
<div
id="div2"></div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)