Posted in Javascript onJanuary 09, 2014
<script> $.schoolFn = { addItem: function(obj){ $("#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>"); }, removeItem: function(obj){ $("#"+obj).replaceWith(""); } } $("#itemAdd").click(function(){ var item=$('#teacherInput').val(); $.schoolFn.addItem(item); $('#teacherInput').val(""); }); function deleteItem(obj){ var item=$(obj).parents(".list-group-item").attr("id"); $.schoolFn.removeItem(item); } </script>
jQuery动态添加、删除元素的方法
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@