以下是我的HTML代码:
<form name="package_type_documents" action="" method="post" enctype="multipart/form-data">
<div class="hor-form">
<ul>
<li>
<div class="answer-block" id="doc_title">
<a href="#" class="c-gray-btn c-add-btn" name="add_more_title" id="add_more_title" onclick="add_title(); return false;"><span>Add More Documents</span></a>
<ol>
<li id="ttl1" class="ptdoc">
<li class="ans_li">
<span class="num-block">1 </span><span class="num-block reqd">*</span>
<label>Document Title</label>
<input type="text" name="pt_doc_title[1]" id="pt_doc_title_1" value="Prabhakar Bhosale" />
</li>
<li class="ans_li">
<span class="num-block"> </span><span class="num-block reqd"> </span>
<label>Document File</label>
<p class="uploadBtn"><input type="file" name="document_file_name_1" id="document_file_name_1"/>
</p>
</li>
<li class="ans_li">
<a href="package_type_documents.php?op=download&pt_id=5&pt_doc_id=19" style="font-size:small;"> prabhakar_bhosale.docx</a>
</li>
<li class="ans_li">
<input type="checkbox" name="delete_file_1" id="delete_file_1" class="custom-check" />
<label for="show">Delete document</label>
</li>
<input type="hidden" name="pt_doc_id[0]" value="19" />
<input type="hidden" name="pt_doc_old_file_iname[0]" value="prabhakar_bhosale.docx" />
</li>
</ol>
<a href="#" class="c-gray-btn c-add-btn" name="add_more_title" id="add_more_title" onclick="add_title(); return false;"><span>Add More Documents</span></a>
<p class="fade">Note * (Image size should be less then 1 mb and allowed image types are jpg, jpeg, gif, png .)</p>
</div>
</li>
<li>
<p class="last">
<input id="saveForm" class="c-btn" type="submit" name="submit" value="Update"/>
<input type="button" class="c-gray-btn" name="back" value="Back" onclick="javascript:window.location.href='http://localhost/eprime/entprm/web/control/modules/package_type/view_package_type.php?page=1'" />
</p>
</li>
</ul>
</div>
</form>
以下是我的jQuery代码:
<script type="text/javascript">
function delete_title(field) {
$('li'+'#'+field).remove();
}
</script>
以下代码未删除相关的
答案 0 :(得分:1)
答案 1 :(得分:0)
试试这个是Javascript:
var elem = document.getElementById('id');
elem.parentNode.removeChild(elem);
答案 2 :(得分:0)
我确信你必须拥有li元素的唯一ID。并使用id删除元素。您可以使用:
$('#'+field).remove();
答案 3 :(得分:0)
$('li').remove();
这将删除所有li元素
及以下代码将从UL中删除特定的Li元素。
`$('#li_yourId').remove();`
答案 4 :(得分:0)
如果要删除具有给定ID的<li>
元素,则可以写:
$('#'+field).remove();
无需写李。