HTML-MOOTOOLS-addoptiontoselectbox在ie6中 请选择产品。。。

HTML-MOOTOOLS-addoptiontoselectbox在ie6中 请选择产品。。。,mootools,Mootools,我在firefox上试用,效果不错 <select id="selectId"> <option>Please select product ...</option> </select> $('selectId')。innertHTML='Test-Test' 但在ie上,它不起作用,如何在ie中按字符串添加选项,如上文所述,请使用元素类: $('selectId').innertHTML = '<option>Test test

我在firefox上试用,效果不错

<select id="selectId">
 <option>Please select product ...</option>
</select>
$('selectId')。innertHTML='Test-Test'

但在ie上,它不起作用,如何在ie中按字符串添加选项,如上文所述,请使用
元素
类:

$('selectId').innertHTML = '<option>Test test</option>'

示例:

如果您打算使用Mootools,那么您应该真正使用Mootools方法,而不是在它和普通Javascript之间切换。这样做的一个好处是Mootools已经为您解决了浏览器不一致的问题。因此,如果你忽视了它的方法,你将不得不自己照顾它们

要以Mootools方式访问元素的属性,可以对任何元素使用和方法。dollar($)函数返回一个元素,这样您就可以链集并获得该元素

new Element('option', {
    text: 'test option'
}).inject($('selectId'));​
//返回selectId的HTML
var foo=$('selectId').get('html');
//将selectId的HTML设置为Test
$('selectId').set('html','Test')//
在这种情况下,您只需要使用set

需要注意的一点是,这不会向选择框中添加选项,而是用选项替换选择框中的所有内容。因此,如果要使用此选项向选择框添加多个选项,则每次重置HTML时,此选项将不起作用。如果选择框只有一个选项,那么它没有多大意义,因此我将假设您正在尝试附加一个选项,而不是用一个选项替换所有内容。在这种情况下,请执行以下操作:

//returns selectId's HTML
var foo = $('selectId').get('html'); 

//Sets the HTML of selectId to <option>Test test</option>
$('selectId').set('html', '<option>Test test</option>'); //
//获取当前选项selectId的选项
var options=$('selectId').get('html');
//在末尾添加您自己的选项
选项=选项+测试;
//将selectId的HTML设置为options中存储的任何内容
$('selectId').set('html',选项);

您确定这不是打字错误吗$('selectId').innertHTML='Test Test'噢,我尝试使用innerHTML,结果相同,即不起作用~.~+1。阅读文档ppl:)我会将
value:nnn
添加到正在传递的对象中。您也可以像预期的那样传递
selected
属性。在这种情况下,您是否尝试使用正确的选项创建一个全新的选择框,删除旧的选择框,然后插入新的选择框?
//get the current options selectId's options
var options = $('selectId').get('html'); 

//Add your own option onto the end
options = options + '<option>Test test</option>';

//Set the HTML of selectId to whatever is stored in options
$('selectId').set('html', options);