[英]how do you extend the stack element in the dom?
正在成功擴展Element
,例如,
Element.prototype.ancestorByTagName = function( tagName ) { ... }
但無法弄清楚如何專門擴展Select
元素
例如,以下每個失敗:
Select.prototype.appendOption = function( value, label, select_value ) { ... }
Element.Select.prototype.appendOption = function( value, label, select_value ) { ... }
茫然。
在這種情況下,將新方法appendOption
限制為Select
而不是All Element
是appendOption
的,因為只有Select
可以具有Option
子項。 Select
的add
方法也很la腳。
這是在Firefox 4中有效的功能
<script>
if (HTMLSelectElement) HTMLSelectElement.prototype.addOption = function(text,value) {
this.options[this.options.length]= new Option(value,text)
}
else alert("It's not called HTMLSelectElement")
window.onload=function() {
document.getElementById('sel1').addOption("Hi","There")
}
</script>
<select id="sel1"></select>
並在IE8中給了我
網頁錯誤詳細信息
Message: 'HTMLSelectElement' is undefined
Line: 2
Char: 1
Code: 0
URI: file:///C:/TEMP/addoption.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.