根据用户选择禁用投递箱 [英] Disable Drop-box Based On Users Selection

查看:60
本文介绍了根据用户选择禁用投递箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我是javascript的新手,想知道是否有人可以帮助我

这个我要禁用我的第二个和第三个如果第一个选择

为已关闭,则下拉框我觉得我很接近,但却无法让它工作

这里是我的代码:

< html>

< head> ;

< title> Untitled Document< / title>

< meta http-equiv =" Content-Type" content =" text / html;

charset = iso-8859-1">

< / head>


< body bgcolor =" #FFFFFF" text ="#000000">


< script>

function DisableMondayDropdown(bool)

{

if(document.Monday.Hours ==" Closed"){

document.Monday.Hours1.disabled = bool;

document.Monday。 Hours2.disabled = bool;

}

}

< / script>


< ; form name = Monday onChange =" DisableMondayDropdown(true)">

< select name = Hours>

< option value = 2> 2

< option value = 3> 3

< option value = 4> 4

< option value = 5> 5

<期权值=关闭>关闭

< / select>


< select name = Hours1>

<期权值= 1> 1

<期权值= 2> 2

<期权值= 3> 3

< option value = 4> 4

< option value = 5> 5

< / select>


< ; select name = Hours2>

< option value = 1> 1

< option value = 2> 2

< option value = 3> 3

< option value = 4> 4

< option value = 5> 5

< / select>


< / form>


< / body>

< / html>


如果你能提前感谢

Blnukem

Hi All

I''m new to javascript and was wondering if someone can help me with
this I want to disable my second and third drop-box if the first one
is selected to "Closed" I think I''m close but just cant get it to work
here is my code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<script>
function DisableMondayDropdown(bool)
{
if(document.Monday.Hours == "Closed"){
document.Monday.Hours1.disabled=bool;
document.Monday.Hours2.disabled=bool;
}
}
</script>

<form name=Monday onChange="DisableMondayDropdown(true)">
<select name=Hours>
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=Closed>Closed
</select>

<select name=Hours1>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
</select>

<select name=Hours2>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
</select>

</form>

</body>
</html>

If you can help thanks in advance
Blnukem

推荐答案

2004年1月18日08:01:11 -0800,Blnukem< bl ***** @ hotmail.com>写道:
On 18 Jan 2004 08:01:11 -0800, Blnukem <bl*****@hotmail.com> wrote:
大家好

我是javascript的新手,想知道是否有人可以帮助我
这我想禁用我的第二个和第三个投递箱,如果第一个投票箱被选择为已关闭,则为第二个和第三个投递箱。我觉得我很接近但是不能让它工作
这里是我的代码:

< html>
< head>
< title> ; Untitled Document< / title>
< meta http-equiv =" Content-Type" content =" text / html;
charset = iso-8859-1">
< / head>

< body bgcolor =" #FFFFFF" text ="#000000">

< script>


SCRIPT元素中需要type属性。你应该改变这个




< script type =" text / javascript">

function DisableMondayDropdown(bool )
{
if(document.Monday.Hours ==" Closed"){


我通常会在此建议您将上述表格引用更改为


document.forms [''Monday'']。elements [''Hours'']


但是,我很有信心韦伯先生会对此有所说明[1],所以我会说b $ b只是说在某些情况下(肯定当id属性是

时),以上语法适用于更多浏览器。

document.Monday.Hours1.disabled = bool;
document.Monday.Hours2.disabled = bool;
}
}
< / script>


我当然建议您将所有属性值括在引号中。

< form name = Monday onChange =" DisableMondayDropdown(true)">


FORM元素没有onchange内部事件。但是,SELECT

元素会这样做,而这就是你要放置属性的位置。

< select name = Hours>
< option value = 2> 2
<选项值= 3> 3
<选项值= 4> 4
<选项值= 5> 5
<选项值=已关闭> ;关闭
< / select>
Hi All

I''m new to javascript and was wondering if someone can help me with
this I want to disable my second and third drop-box if the first one
is selected to "Closed" I think I''m close but just cant get it to work
here is my code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<script>
The type attribute is required in SCRIPT elements. You should change this
to

<script type="text/javascript">
function DisableMondayDropdown(bool)
{
if(document.Monday.Hours == "Closed"){
I would normally recommend here that you change the above form reference to

document.forms[''Monday''].elements[''Hours'']

however, I''m sure Mr Webb would have something to say about it[1], so I''ll
just say that in some circumstances (certainly when id attributes are
involved), the above syntax will work with more browsers.
document.Monday.Hours1.disabled=bool;
document.Monday.Hours2.disabled=bool;
}
}
</script>
I certainly recommend that you enclose all attribute values in quotes.
<form name=Monday onChange="DisableMondayDropdown(true)">
The FORM element doesn''t have an onchange intrinsic event. However, SELECT
elements do, and that''s where you want to place the attribute.
<select name=Hours>
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=Closed>Closed
</select>




< snip>


一旦你做出这些改动,你我会更接近你的目标。但是,

你会注意到没有办法重新启用你禁用的控件。

下面是一个你可以使用的函数(重命名)适应新的

功能。


函数toggleMondayDropdown(){

//获取对表单的引用

var mondayForm = document.forms [''Monday''];

//如果小时为''已关闭'',则禁用控件(状态为true)

var state =(''关闭''== mondayForm.elements [''小时'']。值);


/ *

上面的州的分配也可以写成:


var state;


if(''Closed''= = mondayForm.elements [''Hours'']。value)

{

state = true;

} else {

state = false;

}


如果这使得表达式更清晰。

* /


mondayForm.elements [''Hours1'']。禁用=状态;

mondayForm.elements [''Hours2''] .disable = state;

}


希望有所帮助,


迈克

[1]对韦伯先生:我承认你有一点意见,但我仍然认为我的

推理是有效。是的,当涉及id属性

时,可以使用getElementById(),但并非所有使用的浏览器都支持它(该参数是

迅速减少),并且在表单封闭控件的情况下,有
存在另一种访问id''d控件的方法,我将继续使用

的集合语法。 :)


如果您希望在引用使用

名称而不是ID的情况下我停止推荐它,那么我将(假设快捷语法*与集合语法相比,将*

适用于所有这些情况。)


-

Michael Winter M.******@blueyonder.co.inva 盖子(替换.invalid用.uk回复)



<snip>

Once you make those alterations, you''ll be closer to your goal. However,
you''ll notice that there''s no way to re-enable the controls you disabled.
Below is a function that you can use instead (renamed to fit its new
functionality).

function toggleMondayDropdown() {
// Get a reference to the form
var mondayForm = document.forms[''Monday''];
// If Hours is ''Closed'', disable the controls (state is true)
var state = (''Closed'' == mondayForm.elements[''Hours''].value);

/*
The assignment to state, above, could also be written as:

var state;

if( ''Closed'' == mondayForm.elements[''Hours''].value )
{
state = true;
} else {
state = false;
}

if that makes the expression any clearer.
*/

mondayForm.elements[''Hours1''].disabled = state;
mondayForm.elements[''Hours2''].disabled = state;
}

Hope that helps,

Mike
[1] To Mr Webb: I concede that you have a point, but I still think my
reasoning is valid. Yes, one could use getElementById() when id attributes
are involved, but as not all browsers in use support it (that argument is
rapidly diminishing) and, in the case of form-enclosed controls, there
exists an alternative way to access id''d controls, I''ll continue to use
the collection syntax. :)

If you prefer that I stop recommending it in cases where references use
names, not ids, then I shall (provided that the shortcut syntax *will*
work in all such cases when compared to the collection syntax).

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


" Blnukem" < BL ***** @ hotmail.com>在消息中写道

news:25 ************************** @ posting.google.c om ...
"Blnukem" <bl*****@hotmail.com> wrote in message
news:25**************************@posting.google.c om...
大家好

我是javascript的新手,想知道是否有人可以帮助我
这我想禁用我的第二个和第三个投递箱如果第一个被选择为已关闭的话。我觉得我很接近但是不能让它工作
这里是我的代码:

< html>
< head>
< title> ; Untitled Document< / title>
< meta http-equiv =" Content-Type" content =" text / html;
charset = iso-8859-1">
< / head>

< body bgcolor =" #FFFFFF" text ="#000000">

< script>
函数DisableMondayDropdown(bool)
{
if(document.Monday.Hours =="已结束"){
document.Monday.Hours1.disabled = bool;
document.Monday.Hours2.disabled = bool;
}
}
< / script> ;

< form name = Monday onChange =" DisableMondayDropdown(true)">
< select name = Hours>
< option value = 2> 2
< option value = 3> 3
< option value = 4> 4
< option value = 5> 5
< option value = Closed> Closed
< / select>

< select name = Hours1>
< option value = 1> 1
< option value = 2> 2
< option value = 3> 3
< option value = 4> 4
< option value = 5> 5
< / select>

< ;选择名称=时间2>
<选项值= 1> 1
<选项值= 2> 2
<选项值= 3> 3
< option value = 4> 4
< option value = 5> 5
< / select>

< / form>
< / body>
< / html>

如果你能提前感谢
Blnukem
Hi All

I''m new to javascript and was wondering if someone can help me with
this I want to disable my second and third drop-box if the first one
is selected to "Closed" I think I''m close but just cant get it to work
here is my code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<script>
function DisableMondayDropdown(bool)
{
if(document.Monday.Hours == "Closed"){
document.Monday.Hours1.disabled=bool;
document.Monday.Hours2.disabled=bool;
}
}
</script>

<form name=Monday onChange="DisableMondayDropdown(true)">
<select name=Hours>
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=Closed>Closed
</select>

<select name=Hours1>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
</select>

<select name=Hours2>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
</select>

</form>

</body>
</html>

If you can help thanks in advance
Blnukem




小改动:


1.比较值,而不是元素,用已关闭

2.将onchange处理程序应用于正确的元素(select,不是表格)


函数CheckMondayDropdown()

{

// alert(在变更处理程序中);

document.Monday.Hours1.disabled =(document.Monday.H ours.value ==" Closed");

document.Monday.Hours2.disabled =(document .Monday.H ours.value ==" Closed");

}

< / script>


< ;表格名称=星期一>

<选择名称=小时onChange =" CheckMondayDropdown()">

< option value = 2> 2
< option value = 3> 3

< option value = 4> ; 4

< option value = 5> 5

< option value =已关闭>已关闭

< / select>

....


PS一个方便的提示是添加警报,例如alert(在变更处理程序中);如果你完成了b
你会看到控制没有到达你的onchange

处理程序。



Minor changes:

1. compare value, not element, with "Closed"
2. apply onchange handler to the correct element (the select, not the form)

function CheckMondayDropdown()
{
//alert("In change handler");
document.Monday.Hours1.disabled=(document.Monday.H ours.value == "Closed");
document.Monday.Hours2.disabled=(document.Monday.H ours.value == "Closed");
}
</script>

<form name=Monday>
<select name=Hours onChange="CheckMondayDropdown()">
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=Closed>Closed
</select>
....

PS a handy tip is to add alerts e.g. alert("In change handler"); Had you
done that you would have seen that control was not reaching your onchange
handler.


Michael Winter写道:
Michael Winter wrote:
2004年1月18日08:01:11 -0800,Blnukem< bl ***** @ hotmail.com>写道:


< - snip - >
On 18 Jan 2004 08:01:11 -0800, Blnukem <bl*****@hotmail.com> wrote:

<--snip-->
{
if(
{
if(document.Monday.Hours == "Closed"){



我通常建议您将上面的表格引用更改为

document.forms [ ''星期一'']。元素[''小时'']

然而,我很确定韦伯先生会对此有所说明[1],所以
我'我只是说在某些情况下(当涉及到id属性时),上面的语法将适用于更多的浏览器。


I would normally recommend here that you change the above form reference to

document.forms[''Monday''].elements[''Hours'']

however, I''m sure Mr Webb would have something to say about it[1], so
I''ll just say that in some circumstances (certainly when id attributes
are involved), the above syntax will work with more browsers.




我不喜欢人们说这样的话有问题:


如果你的表单使用ID',那么你使用这种语法更安全。


或:


为了将来的兼容性,请开始学习使用这种语法。


但是,要说它的更好。比起另一个,当使用名称

属性时,是完全错误的。


此代码:


< form id =" myForm" action ="">

< input type =" text" value =" my value" id =" myInput">

< input type =" button" value =" Show Me"

onclick =" alert(document.forms [''myForm'']。elements [''myInput'']。value)"
< / form>


在NN4.xx中完全没用,只要它周围(是的,它仍然是

左右),那么ID属性不应该与Form一起使用。给它一个

名称,以任意方式访问它,继续前进。

< - snip - >


[1]对韦伯先生:我承认你有一点意见,但我仍然认为我的推理是有效的。是的,当涉及id
属性时,可以使用getElementById(),但并非所有使用的浏览器都支持它(
参数正在迅速减少),并且在形式封闭的情况下
控件,存在一种访问id''d控件的替代方法,我会继续使用集合语法。 :)


我从未说过你使用相同语法系统的推理是

有缺陷。我说你的理由是document.forms [''formName''] .....比document.formName更好于
......当命名表格存在时是有缺陷的。

如果你更喜欢我在引用使用
名称而不是id的情况下停止推荐它,那么我将(如果快捷语法*将*
在所有这些情况下工作时)与集合语法相比)。



I don''t have a problem with people saying something like this:

If your form uses ID''s, then you are safer using this syntax.

Or:

For future compatibility, start learning to use this syntax.

But, to say that its "better" than the other, when used with a name
attribute, is plain wrong.

This code:

<form id="myForm" action="">
<input type="text" value="my value" id="myInput">
<input type="button" value="Show Me"
onclick="alert(document.forms[''myForm''].elements[''myInput''].value)" </form>

Is utterly useless in NN4.xx and as long as its around (yes, its still
around), then the ID attribute shouldn''t be used with a Form. Give it a
name, access it either way, and move on.
<--snip-->

[1] To Mr Webb: I concede that you have a point, but I still think my
reasoning is valid. Yes, one could use getElementById() when id
attributes are involved, but as not all browsers in use support it (that
argument is rapidly diminishing) and, in the case of form-enclosed
controls, there exists an alternative way to access id''d controls, I''ll
continue to use the collection syntax. :)
I never said your reasoning for using the same syntax system wide was
flawed. I said your reasoning that document.forms[''formName'']..... was
better than document.formName...... when named forms are present was flawed.
If you prefer that I stop recommending it in cases where references use
names, not ids, then I shall (provided that the shortcut syntax *will*
work in all such cases when compared to the collection syntax).




直到找到无法正常工作的浏览器,然后才有效

使用时有一个名字。


这样的事情怎么样:

< FAQENTRY>

问:如何访问表格元素?

A.如果元素有ID,则使用表单集合:

document.forms [formID] .elements [elementID]

注意:这在旧浏览器中失败。


如果元素具有NAME属性,那么您可以使用表格

集合或快捷语法:


document.forms [''表格名称'']。元素[''elementName'']

或:

document.formName.elementName

< / FAQENTRY>

也许在扩展4.13?


理查德:

这一轮中包含这样的东西已经太晚了<常见问题解答中的
修订版?它似乎最近出现了很多。


-

兰迪



Until a browser is found where it doesn''t work, then either is valid
when used with a name.

How about something like this:
<FAQENTRY>
Q. How do I acces a form element?
A. If the elements have an ID, then use the forms collection:
document.forms[formID].elements[elementID]
Note: This fails in older browsers.

If the elements have a NAME attribute then you can use the forms
collection or the short cut syntax:

document.forms[''formName''].elements[''elementName'']
or:
document.formName.elementName
</FAQENTRY>
Maybe in an expanded 4.13?

Richard:
Is it too late to get something like this incorporated in this round of
revisions to the FAQ? It seems to be coming up a lot recently.

--
Randy


这篇关于根据用户选择禁用投递箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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