枚举元素? [英] enum elements?

查看:76
本文介绍了枚举元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手到js - 我想禁用页面上的所有元素,而新页面是

loading。是否有可能动态枚举元素并禁用

它们?


感谢IA,Simon

Newbie to js - I want to disable all elements on a page whilst a new page is
loading. Is it possible to enumerate the elements dynamically and disable
them?

Thanks IA, Simon

推荐答案




Simon写道:


Simon wrote:
我想禁用页面上的所有元素,而新页面是
加载。是否可以动态枚举元素并禁用它们?
I want to disable all elements on a page whilst a new page is
loading. Is it possible to enumerate the elements dynamically and disable
them?




好​​吧,你可以调用

var all = document。 body.getElementsByTagName(''*'')

查找body元素中的所有元素(使用IE6,Netscape 6/7,Opera

7)。但是我不确定你要为< span>禁用什么或者< p>

元素例如。

当然,只有在解析了
之后你才能找到所有带脚本的元素所以你需要在页面结尾处运行脚本。

如果你知道(例如在内部网上)你的访问者有脚本
启用
,然后使用静态HTML禁用表单控件,例如

< input type =" text"禁用...>

会做,然后在body onload循环中通过document.forms再次启用

元素。


-


Martin Honnen
http: //JavaScript.FAQTs.com/



Well, you can call
var all = document.body.getElementsByTagName(''*'')
to find all elements in the body element (with IE6, Netscape 6/7, Opera
7). I am however not sure what you want to disable for a <span> or <p>
element for instance.
And of course you can only find all those elements with script after
they have been parsed so you would need to run the script at the end of
the page.
If you know (for instance on an intranet) that your visitors have script
enabled then using static HTML to disable form controls e.g.
<input type="text" disabled ...>
will do, then in body onload loop through document.forms to enable
elements again.

--

Martin Honnen
http://JavaScript.FAQTs.com/


>如果您知道(例如在Intranet上)访问者已启用脚本
> If you know (for instance on an intranet) that your visitors have script
,则使用静态HTML禁用表单控件,例如
< input type =" text"禁用...>
将执行,然后在body onload循环通过document.forms再次启用
元素。
enabled then using static HTML to disable form controls e.g.
<input type="text" disabled ...>
will do, then in body onload loop through document.forms to enable
elements again.




感谢Martin - 工作正常,我用这个:


函数DoEnable()

{

var i;

尝试

{

for(i = 0; i< 99999; i ++)

{

document .forms(0).elements(i).disabled = false;

}

}

catch(呃){}

返回true;

}


我的循环有点naff,但我不知道该数字的属性是

元素。


我还想在提交文档时禁用元素。

有一个事件,我可以以某种方式勾选这个吗?


谢谢,Simon



Thanks Martin - that works fine, I use this:

function DoEnable()
{
var i;
try
{
for ( i=0 ; i<99999 ; i++ )
{
document.forms(0).elements(i).disabled = false;
}
}
catch (er) {}
return true;
}

My loop is a bit naff, but I do not know of a property for the number is
elements.

I would also like to disable the elements when the document is submitted. Is
there an event I can somehow hook to do this?

Thanks, Simon


2004年2月19日星期四17:37:31 +0000(UTC),Simon

< si **************** @ btinternet.please。 COM>写道:

[缩进代码]
On Thu, 19 Feb 2004 17:37:31 +0000 (UTC), Simon
<si****************@btinternet.please.com> wrote:
[Indented code]
函数DoEnable()
{
var i;
尝试 {
for(i = 0; i< 99999; i ++)
{


//使用表格的名称代替0会更好

// document.forms [''formName'']

var form = document.forms [0];

var size = form .elements.length;


for(var i = 0; i< size; ++ i){

document.forms(0).elements (i).disabled = false;


表单和元素属性是集合,而不是方法。使用

下标运算符,[]。继续我的重写:


form.elements [i] .disabled = false;

}

}
}
catch(呃){}
返回true;


是否需要退货?

}

我的循环有点不对劲,但我不知道有什么属性数字是
元素。


所有收藏都有属性,长度,描述了

集合的大小。

我也想禁用提交文件时的要素。是否有一个事件,我可以以某种方式钩住这样做?
function DoEnable()
{
var i;
try
{
for ( i=0 ; i<99999 ; i++ )
{
// Using the name of the form in place of 0 would be better
// document.forms[ ''formName'' ]
var form = document.forms[ 0 ];
var size = form.elements.length;

for( var i = 0; i < size; ++i ) {
document.forms(0).elements(i).disabled = false;
The forms and elements properties are collections, not methods. Use the
subscript operators, []. Continuing with my re-write:

form.elements[ i ].disabled = false;
}
}
}
catch (er) {}
return true;
Is the return necessary?
}

My loop is a bit naff, but I do not know of a property for the number is
elements.
All collections have the property, length, which describes the size of the
collection.
I would also like to disable the elements when the document is
submitted. Is there an event I can somehow hook to do this?




FORM元素具有内部事件,onsubmit。这将适合你的
需求。


迈克


-

迈克尔冬天
M.******@blueyonder.co.inva 盖子(替换 ; .invalid" with" .uk" to reply)



FORM elements have the intrinsic event, onsubmit. That will suit your
needs.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)


这篇关于枚举元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆