1
鑑於以下HTML,我試圖刪除所有表單元素。我遇到的問題是select
元素沒有被刪除,而是其中的第一個option
正在被刪除,每次調用刪除代碼。 見http://jsfiddle.net/b8FfT/PrototypeJS不刪除選擇元素
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>
JS
var a = $('order_history_block').parentNode;
$(a).select('input', 'select', 'textarea').invoke('remove');
看起來那會工作。我將如何使用'select()'的輸出來做到這一點?我想避免在那裏硬編碼'select'的ID。 – nachito
我在上面添加了答案 –