<!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=gb2312" />
<title>jquery实现上传页面</title>
<script type="text/javascript" src="../jquery-1.4.1.js"></script>
<script type="text/javascript">
var shu=0//这里定义的必须是全局函数
function tianjia(){
var br=$('<br/>')
var input=$('<input type="file"/>')
//采用字符串拼接的方式
//<input type="button" value="删除文件"/>............这是字符串拼接第一步
//'<input type="button" value="删除文件' '"/>'.........这是字符串拼接第二步,断开
// '<input type="button" value="删除文件'+(++shu)+'"/>'.........第三步
var button=$('<input type="button" value="删除文件'+(++shu)+'"/>')
$("#div1").append(br).append(input).append(button)
button.click(function(){
br.remove()
input.remove()
button.remove()
})
}
</script>
</head>
<body>
<input type="file" /><input type="button" value="添加文件" id="button" onclick="tianjia()"/>
<div id="div1"></div>
</body>
</html>
联系客服