我有一个使用 JQUery 及其类似生成的 Html
<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,必须使用JQuery从.fieldChoices中删除相应的Choice1..
另外,我可能不知道在 JQuery 中我是否单击了 deleteChoice1/deleteChoice2 ,, 所以我不知道如何使用 JQuery 解决它..请建议我....
最佳答案
$(".deleteField").click(function(){
$(this).prevAll("input:first").remove();
$(this).prevAll(".seperator").remove();
$(this).remove();
});
不过,如果将每个选项放在 div 中会更容易。
关于javascript - JQUery 单击中的未知元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1377538/