<div id="fileDiv">
<table id="picTable"></table>
<a href="javascript:void(addPicFile('picTable'));"
class="file">添加图片</a>
*
</div>
<script type="text/javascript">
function addPicFile(idstr) {
currRow=document.getElementById(idstr).insertRow();
cellc=currRow.insertCell();
if(idstr=='picTable')
{
cellcContext= "<input type='file'id ='tt' NAME='file'> <button onclick=\"removePicFile(\'picTable\',this.parentNode.parentNode.rowIndex);\">删除</button><br>";
}
cellc.innerHTML=cellcContext;
}
function removePicFile(idstr,rowIndex){
document.getElementById(idstr).deleteRow(rowIndex);
}
</script>
<table id="picTable"></table>
<a href="javascript:void(addPicFile('picTable'));"
class="file">添加图片</a>
*
</div>
<script type="text/javascript">
function addPicFile(idstr) {
currRow=document.getElementById(idstr).insertRow();
cellc=currRow.insertCell();
if(idstr=='picTable')
{
cellcContext= "<input type='file'id ='tt' NAME='file'> <button onclick=\"removePicFile(\'picTable\',this.parentNode.parentNode.rowIndex);\">删除</button><br>";
}
cellc.innerHTML=cellcContext;
}
function removePicFile(idstr,rowIndex){
document.getElementById(idstr).deleteRow(rowIndex);
}
</script>
本文介绍了一种使用JavaScript实现的图片上传和管理功能。通过在网页上添加图片,并提供了删除已添加图片的功能。此方法适用于需要频繁更新图片内容的应用场景。
1240

被折叠的 条评论
为什么被折叠?



