Home  >  Article  >  Web Front-end  >  How to dynamically add and delete elements with jQuery_jquery

How to dynamically add and delete elements with jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 17:04:43871browse
复制代码 代码如下:

<script> <br>$.schoolFn = { <br>addItem: function(obj){ <br>$("#itemList").append("<li id='liItrm' class='list-group-item clearfix'><span class='glyphicon glyphicon-resize-vertical sort-handle'></span>" obj "<input type='hidden' name='audiences' value='" obj "'><button type='button' class='close delete-btn deleteItem' onclick='deleteItem(this);' title='删除'>×</button></li>"); <br>}, <br><br>removeItem: function(obj){ <br>$("#" obj).replaceWith(""); <br>} <br>} <br>$("#itemAdd").click(function(){ <br>var item=$('#teacherInput').val(); <br>$.schoolFn.addItem(item); <br>$('#teacherInput').val(""); <br>}); <br>function deleteItem(obj){ <br>var item=$(obj).parents(".list-group-item").attr("id"); <br>$.schoolFn.removeItem(item); <br>} <br></script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn