Home > Web Front-end > JS Tutorial > body text

jQuery动态添加、删除元素的方法_jquery

WBOY
Release: 2016-05-16 17:04:43
Original
820 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'>"+obj+"<input type='hidden' name='audiences' value='"+obj+"'><button type='button' class='close delete-btn deleteItem' onclick='deleteItem(this);' title='删除'>×"); <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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!