首页 > 代码库 > 动态添加input功能

动态添加input功能

动态添加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=‘width:330px;‘ readonly=‘readonly‘/>";         str+="<input type=‘button‘ onclick=‘deleteDiv(";         str+=idnum1;         str+=");‘ value=http://www.mamicode.com/‘删除‘>";         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="http://www.mamicode.com/1"/>                     <input id="fileDataValue[0]"  name="fileDataValue[0]" type="text" style="width:330px;" readonly="readonly"/>                     <input type="button" onclick="deleteDiv(0);" value="http://www.mamicode.com/删除">                 </div>             </div>

 <input type="button" id="AddUpload" onclick="TAddFileUpload();" value="http://www.mamicode.com/更多商品图片添加"/> </div>

动态添加input功能