[IE&FireFox兼容]JS對(duì)select操作
更新時(shí)間:2007年01月07日 00:00:00 作者:
今天在Ajax中使用兩個(gè)下拉框動(dòng)態(tài)添加select中的options,當(dāng)我在IE測(cè)試下正常使用卻在FireFox中不能正常使用,我對(duì)腳本也不是很熟悉,所以上網(wǎng)查了一下發(fā)現(xiàn)他們?cè)趧?dòng)態(tài)添加option時(shí)有點(diǎn)不同。
下面把他記下來(lái),說(shuō)不定以后還可以用用:
動(dòng)態(tài)刪除select中的所有options:
function deleteAllOptions(sel){
sel.options.length=0;
}
動(dòng)態(tài)刪除select中的某一項(xiàng)option:
function deleteOption(sel,indx){
sel.options.remove(indx);
}
動(dòng)態(tài)添加select中的項(xiàng)option:
function addOption(sel,text,value){
sel.options.add(new Option(text,value));
}
上面在IE和FireFox都能測(cè)試成功,希望以后你可以用上。
其實(shí)用標(biāo)準(zhǔn)的DOM操作也可以,就是document.createElement,appendChild,removeChild之類的。:)
下面把他記下來(lái),說(shuō)不定以后還可以用用:
動(dòng)態(tài)刪除select中的所有options:
function deleteAllOptions(sel){
sel.options.length=0;
}
動(dòng)態(tài)刪除select中的某一項(xiàng)option:
function deleteOption(sel,indx){
sel.options.remove(indx);
}
動(dòng)態(tài)添加select中的項(xiàng)option:
function addOption(sel,text,value){
sel.options.add(new Option(text,value));
}
上面在IE和FireFox都能測(cè)試成功,希望以后你可以用上。
其實(shí)用標(biāo)準(zhǔn)的DOM操作也可以,就是document.createElement,appendChild,removeChild之類的。:)
相關(guān)文章
通過(guò)ifame指向的頁(yè)面高度調(diào)整iframe的高度
[紅色]通過(guò)ifame指向的頁(yè)面高度調(diào)整iframe的高度...2006-10-10Javascript 文本框textarea高度隨內(nèi)容自適應(yīng)增長(zhǎng)收縮
之前一段時(shí)間項(xiàng)目中用到的一個(gè)功能,用Javascript控制文本框textarea高度隨內(nèi)容自適應(yīng)增長(zhǎng)收縮,今天花了點(diǎn)時(shí)間換了種實(shí)現(xiàn)方法,總結(jié)一下。2011-07-07javascript 09年最新版的省市聯(lián)動(dòng)
省市聯(lián)動(dòng)代碼,最新版。2009-04-04