javascript - JQUery 单击中的未知元素

标签 javascript jquery

我有一个使用 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/

相关文章:

Javascript 在从 iOS 输入和离开选择标签时显示/隐藏固定元素

javascript - 将 forEach 循环中内置的数组数据写回原始对象

javascript - 如何使用 onOpen 触发器脚本更改 Google 表格行为?

javascript - 如何在重定向到另一个页面后显示 react 通知?

javascript - 如何将 jquery 与 Jtable 的自定义输入和显示()一起使用?

javascript - 尝试显示和隐藏元素失败

javascript - 使用 get 请求进行多个数据库查询

javascript - 对象的属性 '$'

javascript - Rails - 使用ajax在div中显示show

javascript - Jquery 在外部 js 文件上未定义