下面是源代码,求大神指教啊!!!<input type="file" name="" id="fileIds1" multiple />
<div id="fangInput"></div><script type="text/javascript">
$("#fileIds1").change(function(){
console.log(1);
var fileObj1 = document.getElementById("fileIds1").files; // js 获取文件对象
for(var i = 0; i < fileObj1.length; i++) {
var btnC = 'del-btn'
$("#fangInput").append('<p for="message-text" class="control-label" style="width: 100%;height:
auto;word-wrap:break-word;word-break:break-all;overflow: hidden">文件名:' +
fileObj1[i].name +
' <button type="button" onclick="fangDelete()" class= btnC style="background-color:#dc4739;color:#fff;margin-top:3px">删除文件</button>');
}
console.log(fileObj1);
})
function fangDelete(){
console.log(event);
var fangInput=document.getElementById("fangInput");
console.log(fangInput);
var lis=fangInput.getElementsByTagName("button");
console.log(lis);
}
</script>这段代码是当Input的值发生变化时,下面的div出现的相应的文件名和一个删除框,我想做到的是点击删除框就能把文件名删了,希望大神解答
3 回答
慕斯709654
TA贡献1840条经验 获得超5个赞
$("#fileIds1").change(function() { console.log(1); var fileObj1 = document.getElementById("fileIds1").files; // js 获取文件对象 for (var i = 0; i < fileObj1.length; i++) { var btnC = 'del-btn' $("#fangInput").append('<p for="message-text" class="control-label" style="width: 100%;height: auto;word-wrap: break-word;word-break:break-all;overflow: hidden">文件名:' + fileObj1[i].name + ' <button type="button" onclick="fangDelete(this)" class= btnC style="background-color:#dc4739;color:#fff;margin-top:3px"> 删除文件</button></p>'); } console.log(fileObj1); }) function fangDelete(t) { $(t).closest("p").remove(); }
慕妹3146593
TA贡献1820条经验 获得超9个赞
$("#fangInput").append('<p for="message-text" class="control-label" id=msg' + i $("p").remove();+ 'style="width: 100%;height: auto;word-wrap:break-word;word-break:break-all;overflow: hidden">文件名:' + fileObj1[i].name + ' <button type="button" onclick="fangDelete(" + i + ")" class= btnC style="background-color:#dc4739;color:#fff;margin-top:3px"> 删除文件</button>'); } function fangDelete(i){ $("#msg" + i).remove(); }
添加回答
举报
0/150
提交
取消