js動態增加刪除上傳附件代碼

來源:互聯網
上載者:User
關鍵字 網頁製作 Ajax 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=gb2312" />
<title>網頁特效動態增加刪除上傳附件代碼</title>
</head>

<body>

js實現多個上傳附件的file檔功能變數代碼
<style type="text/css教程"> .file { font: 10pt; color: black; } </style>
<sc ript language="網頁特效">
      function addfile() {
            var filediv = document.all['filediv'];
           var strhtml = '<span><input type="file" >&nbsp;&nbsp;<button onclick="removefile(parentnode);" >刪除</button><br></span>';
           filediv.innerhtml += strhtml;
      }
     
      function removefile(obj) {
            obj.removenode(true);
      }
</script>
<form enctype="multipart/form-data">
      <div id="filediv"></div>
      <a href="javascript:void(addfile());" class="file ">添加附件</a>
</form>//方法二 像hotmail郵箱增加附件模式動態增加上傳附件代碼

<div id="files">
<div>
<input type=button onclick="add();" value=attacthment>


<script>
var html="<input name=title  type=file> <input type=button value=delete onclick="remove(this)">";
function add()
{
var o=document.all["files"];
var div=document.createelement("div");
div.innerhtml=html;
o.appendchild(div);
div.childnodes[0].click();
}
function remove(obj)
{
obj.parentelement.parentelement.removechild(obj.parentelement);
}
</script>
方法三 js動態增加刪除上傳附件代碼

<style type="text/css"> .file { font: 10pt; color: black; } </style>
<script language="javascript">
var i=0;
function addfile() {
i++;

currrow=conditiontable.insertrow();
cellc=currrow.insertcell();
cellccoNtext= '<input type="file" name="file+"+i>&nbsp;&nbsp;<button onclick="removefile();" >去除</button><br>';
cellc.innerhtml=cellccoNtext;

}
function findtd(o){
if (o.nodename=="tr"|| o.nodename=="table") return;
if(o.nodename=="td")
return (o);
else
return (o.parentelement);
}
function removefile(){
o = findtd(event.srcelement);
alert(o.parentelement.rowindex*1);
conditiontable.deleterow(o.parentelement.rowindex*1);

}
function uploadfile(){

}


</script>
<form enctype="multipart/form-data">
<a href="javascript:void(addfile());" class="file">添加附件</a>  <a href="javascript:void(uploadfile());" class="file">上傳附件</a>
<div id="filediv"  style='height:150px;top:150px;left:0px;overflow-x:auto;overflow-y:auto ;border-style:outset; border-width:1pt;border-color:  black;' >
<table id=conditiontable border=1  >
</table>
</div>

</form>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.