如何确定输入框是否存在而不会出现错误 [英] How to figure out if an input box exists without getting an error

查看:54
本文介绍了如何确定输入框是否存在而不会出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用

alert(parent.MyFrame.document.MyForm.MyInput.value)显示以下输入框的值;


但是如果框架,表格或输入框不存在,我当然会收到一条

错误信息。

如果我显示值之前怎么能弄清楚框架''MyFrame'',

形式''MyForm''以及输入框''MyInput''存在但没有收到

错误消息?


Stefan

I can display the value of the following input box with
alert(parent.MyFrame.document.MyForm.MyInput.value );

But if the frame, the form or the input box doesn''t exist I get of course an
error message.
How can I figure out before I display the value if the frame ''MyFrame'', the
form ''MyForm'' and also the input box ''MyInput'' exists without getting an
error message?

Stefan

推荐答案




Stefan Mueller写道:


Stefan Mueller wrote:
我可以用
alert(parent.MyFrame.document.MyForm.MyInput.value)显示以下输入框的值;

但是如果框架,表格或输入框不存在我当然会收到错误消息。
I can display the value of the following input box with
alert(parent.MyFrame.document.MyForm.MyInput.value );

But if the frame, the form or the input box doesn''t exist I get of course an
error message.




使用对象/特征检测:

< http://jibbering.com/faq/#FAQ4_26>

T帽子FAQ主要是关于检查浏览器实现的某些功能

但是这些属性或对象检查也可以应用于你的问题。

那里有一个例子。 />

-


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


Stefan Mueller写道:
Stefan Mueller wrote:
我可以使用
alert(parent.MyFrame.document.MyForm.MyInput.value)显示以下输入框的值;

但是如果框架,表单或输入框没有''存在我当然是一个
错误信息。
如果框架''MyFrame'',
形成''MyForm'',我怎么能在显示值之前搞清楚输入框''MyInput''是否存在而没有收到错误消息?
I can display the value of the following input box with
alert(parent.MyFrame.document.MyForm.MyInput.value );

But if the frame, the form or the input box doesn''t exist I get of course an
error message.
How can I figure out before I display the value if the frame ''MyFrame'', the
form ''MyForm'' and also the input box ''MyInput'' exists without getting an
error message?




也许类似的东西..


函数myFoo()

{

for(;;){

if(parent.MyFrame)if(parent.MyFrame.document)

if (parent.MyFrame.document.getElementById(" MyInput"))

break;


setTimeout(" myFoo()",1000) ;返回;

} //永远结束

alert(parent.MyFrame.document.MyForm.MyInput.value);

}

-

- 。

- =<> Clue博士(A.K.A. Ian A. Storms)<> = - C ++,HTML,CSS,Javascript

- =<>自1994年以来的互联网编程<> = - DHTML NSAPI TCP / IP

- =<> http://resume.drclue.net <> = - AJAX,SOAP, XML,HTTP

- =<> http://www.drclue.net <> = - SERVLETS,TCP / IP,SQL

- 。



Perhaps something similar to this..

function myFoo()
{
for(;;) {
if(parent.MyFrame)if(parent.MyFrame.document)
if(parent.MyFrame.document.getElementById("MyInput "))
break;

setTimeout("myFoo()",1000);return;
}// End forever
alert(parent.MyFrame.document.MyForm.MyInput.value );
}
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.


Clue博士写道:
Dr Clue wrote:
也许类似于此..


当然不是!

函数myFoo()
{
for(;;){
if( parent.MyFrame)if(parent.MyFrame.document)
if(parent.MyFrame.document.getElementById(" MyInput"))
break;


我很少看到这么荒谬的源代码。


1.紧密循环是走向黑暗面的方式。[tm ]


2. if(parent.MyFrame)if(parent.MyFrame.document)

if(parent.MyFrame.document.getElementById(" MyInput) ))


可以而且应该表示为


if(parent.frames [''MyFrame'']

&& parent.MyFrame.document


setTimeout(" myFoo()",1000); return;
Perhaps something similar to this..
Certainly not!
function myFoo()
{
for(;;) {
if(parent.MyFrame)if(parent.MyFrame.document)
if(parent.MyFrame.document.getElementById("MyInput "))
break;
I have seldom seen such a ridiculous piece of source code.

1. Tight loops are the way to the Dark Side.[tm]

2. if(parent.MyFrame)if(parent.MyFrame.document)
if(parent.MyFrame.document.getElementById("MyInput "))

can and should be expressed as

if (parent.frames[''MyFrame'']
&& parent.MyFrame.document

setTimeout("myFoo()",1000);return;




认真思考这一分钟!你在这里设置了数千个

超时(因为它运行的时间很紧),以便在1000毫秒内完成

(1秒)之后.CPU的速度越快,大约_same_时间的时间就会超过

。然后它还没有结束,因为每个都是b / b
这些成千上万的超时会设置更多的超时_each_这将为b $ b设置更多的超时...作为myFoo()总是如此再次打来电话。这将是至少100万次超时的b $ b!一个确定的方法来削弱用户的

系统无法修复。


先生,自称是Clue博士,根本没有任何线索。或者你有一个

的线索,故意想要伤害他人,谁知道呢。事实是:你是
危险。很长一段时间你应该被判无法访问计算机

。 FOAD!

PointedEars



Seriously think about that for a minute! You set probably thousands of
timeouts here (since it runs in a tight loop) to go off 1000 milliseconds
(1 second) later. The faster the CPU is, the more timeouts will go off at
approximately the _same_ time. And then it is not over because each of
these thousands of timeouts will set even more timeouts _each_ which will
set more timeouts which ... as myFoo() always called again. That will be
probably 1 million timeouts at the least! A sure way to cripple the user''s
system beyond repair.

You sir, who calls himself Dr Clue, have no clue at all. Or you have a
clue and deliberately want harm others, who knows. The fact is: You are
dangerous. You should be condemned to have no computer access at all
for a very long time. FOAD!
PointedEars


这篇关于如何确定输入框是否存在而不会出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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