先看以下代码:
<html>
<head>
<script language="JavaScript">
function init()
{
if(document.all('items')==null){
alert('items is null');
}else{
alert('items is not null ,is :'+document.all('items'));
}
//现在document.all('items')仍然为空
var v_items = document.getElementsByName('items');
if(v_items==null){
alert('v_items is null');
}else{
alert('v_items is not null , is : '+v_items);
}
if(document.all('items')==null){
alert('items is null');
}else{
alert('items is not null ,is :'+document.all('items'));
}
//现在document.all('items')为什么不为空了呢?
}
</script>
</head>
<body onLoad="init();"></body>
</html>为什么在调用document.getElementsByName('items');之前document.all('items')等于null,而在调用之后document.all('items')就不为空了呢?
<html>
<head>
<script language="JavaScript">
function init()
{
if(document.all('items')==null){
alert('items is null');
}else{
alert('items is not null ,is :'+document.all('items'));
}
//现在document.all('items')仍然为空
var v_items = document.getElementsByName('items');
if(v_items==null){
alert('v_items is null');
}else{
alert('v_items is not null , is : '+v_items);
}
if(document.all('items')==null){
alert('items is null');
}else{
alert('items is not null ,is :'+document.all('items'));
}
//现在document.all('items')为什么不为空了呢?
}
</script>
</head>
<body onLoad="init();"></body>
</html>为什么在调用document.getElementsByName('items');之前document.all('items')等于null,而在调用之后document.all('items')就不为空了呢?
解决方案 »
- WEB代码求助?....
- 请高手帮助解决,最好能给出源码,谢谢了!
- 求助。点击网页上的提交按钮后,get提交的URL是按什么规则生成的??
- 高手请进,关于firefox的问题
- 如何循环读表格?我不知道页面有几个表格,我用一个循环把内容都给读出来
- 如何判断页面上的值是否发生变化
- 用Select 选择一个值时,怎样显示该值对应的内容
- 在JavaScript中如何使用treeview啊
- 怎么样实现post方式把参数传递到window.open新开页面中(不用get,是因为我传递参数容量太大)???
- 鼠标放在文字上面就显示相应的图片问题
- Active X能在USB盾上读取/写入数据嗎?
- 我想问一下Javascript 中的range对象怎么用的~
不管'items'元素存在否,都会创建/返回name='items'的元素集合(type=[object]),如果'items'元素不存在集合--[object].length=0,或者'items'元素存在N个[object].length=Ndocument.all('items')是对name='items'的元素集合的引用,如果存在name='items'的元素,系统会自动创建因此,
第一段,name='items'的元素不存在,系统不会创建name='items'的元素集合,document.all('items')得到null
第二段,document.getElementsByName('items')创建/返回name='items'的元素集合(name='items'的元素不存在,此时集合长度=0)
第三段document.all('items')直接引用name='items'的元素集合(已经存在),得到[object]
顺便问一下有官方文档吗?我查的都是之说“返回”元素,没有提到“创建”元素。
难道 FF 实现 getElementByName 创建后又删除了?