首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PrototypeJS不移除选择元素

PrototypeJS不移除选择元素
EN

Stack Overflow用户
提问于 2013-10-30 14:24:27
回答 1查看 695关注 0票数 1

考虑到下面的HTML,我尝试删除所有的表单元素。我遇到的问题是,select元素没有被删除,而是在每次调用remove代码时删除其中的第一个option。请参阅http://jsfiddle.net/b8FfT/

代码语言:javascript
复制
<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>

JS

代码语言:javascript
复制
var a = $('order_history_block').parentNode;
$(a).select('input', 'select', 'textarea').invoke('remove');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-30 15:21:49

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

你有2个选择

代码语言:javascript
复制
$('history_status').parentNode.removeChild($('history_status'));

代码语言:javascript
复制
Element.remove($('history_status'));

我也为此提交了一份错误报告

https://github.com/sstephenson/prototype/issues/122

编辑

使用CSS选择器和select()方法,如

代码语言:javascript
复制
$('order_history_block').up().select('select').each(function(item){
    Element.remove(item);
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19684961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档