2009-09-04 10 views
0
나는 HTML을 생성하여 jQuery를하고 내가 deleteChoice1의 클릭에 해당 Choice1가 JQuery와 사용 .fieldChoices에서 제거해야합니다 함께 노력하고

알 수없는 요소는 클릭

<p class="fieldChoices title" style=""> 
    Choices: 
    <input id="Choice1" value="option1" maxlength="150"/> 
    <div class="seperator"/> 
    <p class="deleteChoice1 cutsom_button deleteField"></p> 
    <div class="seperator"/> 
    <input id="Choice2" value="option2" maxlength="150"/> 
    <div class="seperator"/> 
    <p class="deleteChoice2 cutsom_button deleteField"></p> 
    <div class="seperator"/> 
</p> 

을 같은 ..

을 데

내가 deleteChoice1/deleteChoice2을 클릭하고 있는지

또한 내가 .... 그래서 난 나를 JQuery..please를 사용하여 해결 제안하는 방법을 잘 모릅니다,, JQuery와에 알 수 없습니다

답변

2
$(".deleteField").click(function(){ 
    $(this).prevAll("input:first").remove(); 
    $(this).prevAll(".seperator").remove(); 
    $(this).remove(); 
}); 

div에 각 선택을 넣는 것이 더 쉽지만.

1

는 대신 다음보십시오 :

<p class="fieldChoices title" style=""> 
    Choices: 
    <fieldset> 
    <input id="Choice1" value="option1" maxlength="150"/> 
    <div class="seperator"/> 
    <span class="cutsom_button deleteField"></span> 
    </fieldset> 
    <fieldset> 
    <input id="Choice2" value="option2" maxlength="150"/> 
    <div class="seperator"/> 
    <span class="cutsom_button deleteField"></span> 
    </fieldset> 
</p> 

$("deleteField").bind("click", function(){ 
    $(this).parent().remove(); 
} 
+0

오 좋은 전화. 그렇지 않으면 외부 요소가 유지됩니다. 내 편집해야 해! – Anthony

0

HTML :

<fieldset class="fieldChoices title"> 
    <legend>Choices</legend> 
    <ul> 
    <li> 
     <input id="Choice1" value="option1" maxlength="150"/> 
     <span class="deleteChoice cutsom_button deleteField"></span> 
    </li> 
    <li> 
     <input id="Choice2" value="option2" maxlength="150"/> 
     <span class="deleteChoice cutsom_button deleteField"></span> 
    </li> 
    </ul> 
</fieldset> 

JQuery와 :

$(".fieldChoices li").each(function() { 
     var choice = $(this); 
     $(".deleteChoice", this).click(function() { 
      choice.remove(); 
     }); 
     });