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

How to dynamically add and delete elements with jQuery_jquery

WBOY
Release: 2016-05-16 17:04:43
Original
896 people have browsed it
复制代码 代码如下:

<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>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template