<div class="codetitle"> <span><a style="CURSOR: pointer" data="34249" class="copybut" id="copybut34249" onclick="doCopy('code34249')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code34249"> <br><script type="”text/javascript”" src="%E2%80%9Djquery.js=%E2%80%9Djquery."></script><br><br><form action="%E2%80%9D%22" method="”post”" enctype="”multipart/form-data”"> <br><label>請選擇上傳的圖片</label><br><a href="%E2%80%9Djavascript:addimg()%E2%80%9D">增加圖片</a><br><div class="”mdiv”" id="”mdiv”"> <br><div class="”iptdiv”"> <br><input type="”file”" name="”img[]”" class="”ipt”"><a href="%E2%80%9D#%E2%80%9D" name="%E2%80%9Drmlink%E2%80%9D">X</a><br> </div> <br> </div> <br><input type="”submit”" name="”submit”" value="”上傳圖片”"><br> </form> <br><script type="”text/javascript”"><BR>$(document).ready(function(){<BR>bindListener();<BR>});<BR>// 用來綁定事件(使用unbind避免重複綁定)<BR>function bindListener() {<BR>$(“a[name=rmlink]“).unbind().click(function(){<BR>$(this).parent().remove();<BR>})<BR> }<BR>function addimg(){<BR>$(“#mdiv”).append('<div class=”iptdiv”><input type=”file” name=”img[]” class=”ipt” /><a href=”#” name=”rmlink”> X </script> </div>');<br>// 為新元素節點新增事件偵聽器<br>bindListener();<br>}<br><br>