动态添加input功能:
<script> var TfileUploadNum=3; //记录图片选择框个数 var Tnum=3; //ajax上传图片时索引 function TAddFileUpload() { var idnum1 = TfileUploadNum+1; var idnum2 = TfileUploadNum+2; var str="<div id='fileDataDiv["; str+=idnum1; str+="]' class='module_border'><div class='l'> 商品图片"; str+=idnum2; str+=":</div><div class='c'><input id='fileData["; str+=idnum1; str+="]' name='fileData["; str+=idnum1; str+="]' type='file' onchange='StatusValuesFunctiong("; str+=idnum1; str+=");'"; str+="class='input_border'/>"; str+="<input id='fileDataValue["; str+=idnum1; str+="]' name='fileDataValue["; str+=idnum1; str+="]' type='text' style='330px;' readonly='readonly'/>"; str+="<input type='button' onclick='deleteDiv("; str+=idnum1; str+=");' value='删除'>"; str+="</div></div>"; $('#provincecode').append(str); TfileUploadNum += 1; }
function deleteDiv(statusValue){ document.getElementById("fileDataDiv["+statusValue+"]").style.display='none'; } </script>
<div id="provincecode" class="module_border"> <div id="fileDataDiv[0]" class="module_border"> <div class="l"> 商品图片1: </div> <div class="c"> <input id="fileData[0]" name="fileData[0]" type="file" onchange="StatusValuesFunctiong(0);" value="1"/> <input id="fileDataValue[0]" name="fileDataValue[0]" type="text" style="330px;" readonly="readonly"/> <input type="button" onclick="deleteDiv(0);" value="删除"> </div> </div>
<input type="button" id="AddUpload" onclick="TAddFileUpload();" value="更多商品图片添加"/> </div>