点击按钮more... ,就 生成一个新的上传文件框。
<html>
<head><script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
//use javascript to do it
/*
var addMore = function()
{
var br = document.createElement("br");
var input = document.createElement("input");
input.setAttribute("type","file");
var button = document.createElement("input");
button.setAttribute("type","button");
button.setAttribute("value","Remove");
var div = document.getElementById("div1");
button.onclick = function(){
div.removeChild(br);
div.removeChild(input);
div.removeChild(button);
};
div.appendChild(br);
div.appendChild(input);
div.appendChild(button);
}
*/
//use jQuery to do it
$(function()
{
$("input[type=button]").click(function()
{
var br = $("<br>");
var input = $("<input type='file'>");
var button = $("<input type='button' value='Remove" + (++count) + " '>");
$("#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="more..." οnclick="addMore();"> -->
<input type="button" value="more...">
<div id="div1"></div>
</body>
</html>
点击按钮more... ,就 生成一个新的上传文件框。
运行结果实例为: