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>


你可能感兴趣的:(jquery)