Javascript PrototypeJS不删除选择元素

Javascript PrototypeJS不删除选择元素,javascript,prototypejs,Javascript,Prototypejs,给定以下HTML,我将尝试删除所有表单元素。我遇到的问题是,没有删除select元素,而是每次调用remove代码时都会删除其中的第一个选项。 看 HTML <fieldset> <div id="order_history_block"> <div id="history_form" class="order-history-form"> <div>Add Order Comments</div>

给定以下HTML,我将尝试删除所有表单元素。我遇到的问题是,没有删除
select
元素,而是每次调用remove代码时都会删除其中的第一个
选项。
看

HTML

<fieldset>
  <div id="order_history_block">
    <div id="history_form" class="order-history-form">
      <div>Add Order Comments</div>
      <span class="field-row">
        <label class="normal" for="history_status">Status</label><br>
        <select name="history[status]" class="select" id="history_status">
          <option value="processing">Ok to Ship</option>
          <option value="pending" selected="selected">Pending</option>
        </select>
      </span>
      <span class="field-row">
          <label class="normal" for="history_comment">Comment</label>
          <textarea name="history[comment]" rows="3" cols="5" style="height:6em; width:99%;" id="history_comment"></textarea>
      </span>
      <div class="f-left">
        <input name="history[is_visible_on_front]" type="checkbox" id="history_visible" value="1"><label class="normal" for="history_visible"> Visible on Frontend</label>
      </div>
      <div class="f-right">
        <button id="id_79ae3bd75916862b0245fbcb3343d24e" title="Submit Comment" type="button" class="scalable save" onclick="doStuff()" style=""><span><span><span>Submit Comment</span></span></span></button>
      </div>
      <div class="clear"></div>
    </div>
    <div class="divider"></div>
    <!-- ... -->
  </div>
</fieldset>

因此,HTMLSelectElement原型(不是框架)有自己的
remove()
方法,当您在
s上调用
remove()
时,它不会沿着原型链向上遍历PrototypeJS添加的HTMLElement的
remove()
方法

你有两个选择

$('history_status').parentNode.removeChild($('history_status'));

我也为此提交了一份bug报告

编辑

像这样使用CSS选择器和
select()
方法

$('order_history_block').up().select('select').each(function(item){
    Element.remove(item);
});

因此,HTMLSelectElement原型(不是框架)有自己的
remove()
方法,当您在
s上调用
remove()
时,它不会沿着原型链向上遍历PrototypeJS添加的HTMLElement的
remove()
方法

你有两个选择

$('history_status').parentNode.removeChild($('history_status'));

我也为此提交了一份bug报告

编辑

像这样使用CSS选择器和
select()
方法

$('order_history_block').up().select('select').each(function(item){
    Element.remove(item);
});

看起来这样行。如何使用
select()
的输出来执行此操作?我想避免在那里硬编码
选择
的ID。我在上面添加了答案,看起来这样行。如何使用
select()
的输出来执行此操作?我想避免在那里硬编码
选择
的ID。我在上面添加了答案