2012-05-18 54 views
0

我有一個頁面,有一個鏈接,如果用戶點擊鏈接,一個新的選擇標籤將出現,並離開那個選擇,將有一個刪除鏈接,如果用戶點擊它,選擇標記將消失jquery kill元素,而不是隱藏

我的問題是,當我點擊創建一個新的選擇,然後單擊刪除它,真的它不會被刪除,它只是隱藏,我不想那個COS後提交我檢查是否有新的選擇設置,所以我得到真正的COS它只是被隱藏了不刪除,如何解決取悅

HTML代碼

<div class="container" id="addCell"> 
    <form method="POST" action="<?php echo URL; ?>Cell/addCell"> 
     <ul> 
      <li> 
       <p> 
        <label>Name</label> 
        <input type="text" name="name"class="longInput1"/> 
       <p> 
       <p> 
        <label>City</label> 
        <select id="countrySelector" name="city"> 
        </select> 
       </p> 
      </li> 
      <li> 
       <p> 
        <label>Inserted cells</label> 
        <a href="#" class="smallLink" id="acaclink">new</a> 
       </p> 
      </li> 
      <li> 
       <input type="submit" class="button1" value="save"/> 
      </li> 
     </ul> 
    </form> 
</div> 

數據庫代碼

public function addCell() { 
     $cellName = $_POST['name']; 
     $cityName = $_POST['city']; 
     $this->model->addCell($cellName, $cityName); 
     if (isset($_POST['acSelect'])) { 
      $cells = $_POST['acSelect']; 
      $cellID = $this->model->getCellID($cellName); 
      $this->model->insertIntersectionCells($cellID, $cells); 
     } 
     include_once 'Successful.php'; 
     $s = new Successful(); 
     $s->index("you inserted your cell"); 
    } 

$ jQuery代碼#

$("#addCell").ready(function(){ 
    $("#addCell").on('click',"#acaclink",function(){ 
     var me = this; 
     $.getJSON("http://localhost/Mar7ba/Cell/getAllCells/TRUE",function(data){ 
      var options = ''; 
      options+="<option>select cell</option>"; 
      for(var i=0;i<data.length;i++){ 
       options += "<option>"+data[i]+"</option>"; 
      } 
      $(me).closest('li').append('<p>\n\ 
      <label>Select Cell</label>\n\ 
      <select name="acSelect[]">\n\ 
      '+options+'\n\ 
</select>\n\ 
<a href="#" class="removeA">delete</a>\n\ 
</p>'); 
     }); 
    }); 
}); 
$("#addCell").ready(function(){ 
    $("#addCell").on('click',".removeA",function(){ 
     $(this).closest('p').hide(); 
    }); 
}); 

我希望我能解釋我的問題COS我的英語不好

回答

3

您可以使用remove()方法:

$("#addCell").ready(function(){ 
    $("#addCell").on('click',".removeA",function(){ 
     $(this).closest('p').remove(); 
    }); 
}); 
+0

是的,它的工作原理,謝謝你,我會接受答案 –