论坛首页 Web前端技术论坛

IE script操作html object的方法,属性可以看msdn,firefox得...

浏览 6993 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-08-08  
ie下select得到所有option的方法就是
obj.options

firefox下报错,firefox的相应方法是什么呢?
   发表时间:2005-08-08  
chenggn 写道
ie下select得到所有option的方法就是
obj.options

firefox下报错,firefox的相应方法是什么呢?


报什么错误呢?firefox也是sel.options[0]这样去取
0 请登录后投票
   发表时间:2005-08-09  
知道了

firefox只有dom操作

ou.options.appendChild

没有 option.add() 方法

文档见 http://www.mozilla.org/docs/dom/
0 请登录后投票
   发表时间:2005-08-09  
chenggn 写道
知道了

firefox只有dom操作

ou.options.appendChild

没有 option.add() 方法

文档见 http://www.mozilla.org/docs/dom/


Firefox下绝对可以的:
var opt = new Option(weekid,weekid+","+i);
sel.options.add(opt);
0 请登录后投票
   发表时间:2005-08-09  
你说的确实可以。下午大概是缓存问题。

不过remove还是不行? 有一段代码如下

var ou = document.getElementById("skills");

do {
      for (i = 0; i < ou.options.length; i++) {
ou.options.remove(i);
      }
} while (ou.options.length > 0)

他说ou.options.remove not a function

不过同一叶面其他的remove却可以。
0 请登录后投票
   发表时间:2005-08-09  
chenggn 写道
你说的确实可以。下午大概是缓存问题。

不过remove还是不行? 有一段代码如下

var ou = document.getElementById("skills");

do {
      for (i = 0; i < ou.options.length; i++) {
ou.options.remove(i);
      }
} while (ou.options.length > 0)

他说ou.options.remove not a function

不过同一叶面其他的remove却可以。


你每删除一个length会变化的,事事以下代码

var l = ou.options.length
for (i = 0; i <l; i++); {
	ou.options.remove(0);;
      }	
0 请登录后投票
   发表时间:2005-08-12  
处理option的时候,我喜欢这样:

options[options.length-1] = new Option(x,x);

同样的,只要是数组,都可以这样处理。
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics