jQuery动态添加、删除元素的方法。代码如下:
<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>
网友评论文明上网理性发言 已有0人参与
发表评论: