使用Javascript禁用按钮 [英] Disable Button With Javascript

查看:75
本文介绍了使用Javascript禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


在我的C#asp.net 2.0应用程序中,我有一个带按钮服务器的webform

控制它。与网站上的其他大多数人一样,webform订阅了一个母版页。

。我已经确定按钮总是呈现为ct100_ContentPlaceHolder1_btnContinue的

id。在IE和

Firefox浏览器中。


我在

页面加载时创建了以下javascript代码段来禁用它。我有理由不想用服务器端这样做

代码...


document.all [''ct100_ContentPlaceHolder1_btnContinue'']。disabled = true ;


现在,当我在IE中查看时,按钮被禁用。但是当我在Firefox中查看它时,它不是.b $ b。此外,

浏览器也没有返回javascript错误。此外,我已经在

web.config中更新了我的browserCaps部分,如果这是相关的。


为什么在查看页面时按钮保持启用状态Firefox?

Hello,

In my C# asp.net 2.0 application, I have a webform with a button server
control on it. The webform, like most others in the site, subscribes to
a master page. I have determined that the button always renders with an
id of "ct100_ContentPlaceHolder1_btnContinue" in both the IE and
Firefox browsers.

I created the following javascript code segment to disable it when the
page loads. I have reasons for not wanting to do this with server side
code...

document.all[''ct100_ContentPlaceHolder1_btnContinue''].disabled = true;

Now, when I view this in IE, the button is disabled. But when I view it
in Firefox, it''s not. Also, there are no javascript errors returned by
either browser. Also, I have already updated my browserCaps section in
web.config, if that is relevant.

Why does the button remain enabled when viewing the page with Firefox?

推荐答案

你需要在代码后面实际查询,以确定回发内容

event用于控件并相应地发出JavaScript。我不确定

它可以克服所有Firefox问题,但即使你出于某种原因重命名控件,它也能确保在

兔子洞中找到正确的路径。我没有这样的

样本。


如果你必须绝对通用,你可以获得发布的控件
$ b来自Request [" EVENTTARGET"]的$ b,但这并不适用于所有控件。


-

Gregory A. Beamer

MVP; MCP:+ I,SE,SD,DBA


**************************** *********************

在盒子外面思考!

******* ****************************************** *

"乔伊" < jo ********* @ topscene.comwrote in message

news:11 ********************* *@h48g2000cwc.googlegr oups.com ...
YOu need to actually query, in code behind, to determine what the postback
event is for the control and emit the JavaScript accordingly. I am not sure
this conquers all Firefox issues, but it guarantees a proper path down the
rabbit hole even if you rename the control for some reason. I do not have a
sample for this.

If you have to go absolutely generic, you can get the control that posted
from Request["EVENTTARGET"], but this does not work with all controls.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"Joey" <jo*********@topscene.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

您好,


在我的C#asp.net 2.0应用程序中,我有一个带按钮服务器的webform

控制它。与网站上的其他大多数人一样,webform订阅了一个母版页。

。我已经确定按钮总是呈现为ct100_ContentPlaceHolder1_btnContinue的

id。在IE和

Firefox浏览器中。


我在

页面加载时创建了以下javascript代码段来禁用它。我有理由不想用服务器端这样做

代码...


document.all [''ct100_ContentPlaceHolder1_btnContinue'']。disabled = true ;


现在,当我在IE中查看时,按钮被禁用。但是当我在Firefox中查看它时,它不是.b $ b。此外,

浏览器也没有返回javascript错误。此外,我已经在

web.config中更新了我的browserCaps部分,如果这是相关的。


为什么在查看页面时按钮保持启用状态Firefox?
Hello,

In my C# asp.net 2.0 application, I have a webform with a button server
control on it. The webform, like most others in the site, subscribes to
a master page. I have determined that the button always renders with an
id of "ct100_ContentPlaceHolder1_btnContinue" in both the IE and
Firefox browsers.

I created the following javascript code segment to disable it when the
page loads. I have reasons for not wanting to do this with server side
code...

document.all[''ct100_ContentPlaceHolder1_btnContinue''].disabled = true;

Now, when I view this in IE, the button is disabled. But when I view it
in Firefox, it''s not. Also, there are no javascript errors returned by
either browser. Also, I have already updated my browserCaps section in
web.config, if that is relevant.

Why does the button remain enabled when viewing the page with Firefox?



Joey,


此代码适用于我。务必将您的DTD声明为XHTML 1.1

Transitional。您可能会发现这有帮助,因为处理残疾

属性的方式自HTML 3.2规范以来已发生变化。


< script type =" text / javascript">

<! -

function disableButton(buttonId){

if(document.all){

var btn = document.all [buttonId; btn.disabled =''true'';

}

else {

var btn = document.getElementById(buttonId); btn.disabled =''true'';

}

}

// - >

< / script>


....


<! - 定义按钮后 - >

< script type =" text / javascript">

disableButton(''ct100_ContentPlaceHolder1_btnContin ue'');

< / script>

Brennan Stehling
http://brennan.offwhite.net / blog /


Joey写道:
Joey,

This code works for me. Be sure to declare your DTD as XHTML 1.1
Transitional. You may find that helps because the way the disabled
attribute was handled has changed since the HTML 3.2 spec.

<script type="text/javascript">
<!--
function disableButton(buttonId) {
if (document.all) {
var btn = document.all[buttonId; btn.disabled = ''true'';
}
else {
var btn = document.getElementById(buttonId); btn.disabled = ''true'';
}
}
// -->
</script>

....

<!-- After button is defined -->
<script type="text/javascript">
disableButton(''ct100_ContentPlaceHolder1_btnContin ue'');
</script>
Brennan Stehling
http://brennan.offwhite.net/blog/

Joey wrote:

你好,


在我的C#asp.net 2.0应用程序中,我有一个带有按钮服务器的webform

控件。与网站上的其他大多数人一样,webform订阅了一个母版页。

。我已经确定按钮总是呈现为ct100_ContentPlaceHolder1_btnContinue的

id。在IE和

Firefox浏览器中。


我在

页面加载时创建了以下javascript代码段来禁用它。我有理由不想用服务器端这样做

代码...


document.all [''ct100_ContentPlaceHolder1_btnContinue'']。disabled = true ;


现在,当我在IE中查看时,按钮被禁用。但是当我在Firefox中查看它时,它不是.b $ b。此外,

浏览器也没有返回javascript错误。此外,我已经在

web.config中更新了我的browserCaps部分,如果这是相关的。


为什么在查看页面时按钮保持启用状态火狐?
Hello,

In my C# asp.net 2.0 application, I have a webform with a button server
control on it. The webform, like most others in the site, subscribes to
a master page. I have determined that the button always renders with an
id of "ct100_ContentPlaceHolder1_btnContinue" in both the IE and
Firefox browsers.

I created the following javascript code segment to disable it when the
page loads. I have reasons for not wanting to do this with server side
code...

document.all[''ct100_ContentPlaceHolder1_btnContinue''].disabled = true;

Now, when I view this in IE, the button is disabled. But when I view it
in Firefox, it''s not. Also, there are no javascript errors returned by
either browser. Also, I have already updated my browserCaps section in
web.config, if that is relevant.

Why does the button remain enabled when viewing the page with Firefox?


document.all是一个仅限IE的集合,它在w3c

标准中不存在,所以它适用于ie只要。使用w3c标准:


document.getElementById(''ct100_ContentPlaceHolder1 _btnContinue'')。disabled =

true;


- 布鲁斯(sqlwork.com)


" Joey" < jo ********* @ topscene.comwrote in message

news:11 ********************* *@h48g2000cwc.googlegr oups.com ...
document.all is an IE only collection, it does not exist in the w3c
standard, so it works in ie only. use the w3c standard:

document.getElementById(''ct100_ContentPlaceHolder1 _btnContinue'').disabled =
true;

-- bruce (sqlwork.com)

"Joey" <jo*********@topscene.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

您好,


在我的C#asp.net 2.0应用程序中,我有一个带按钮服务器的webform

控制它。与网站上的其他大多数人一样,webform订阅了一个母版页。

。我已经确定按钮总是呈现为ct100_ContentPlaceHolder1_btnContinue的

id。在IE和

Firefox浏览器中。


我在

页面加载时创建了以下javascript代码段来禁用它。我有理由不想用服务器端这样做

代码...


document.all [''ct100_ContentPlaceHolder1_btnContinue'']。disabled = true ;


现在,当我在IE中查看时,按钮被禁用。但是当我在Firefox中查看它时,它不是.b $ b。此外,

浏览器也没有返回javascript错误。此外,我已经在

web.config中更新了我的browserCaps部分,如果这是相关的。


为什么在查看页面时按钮保持启用状态Firefox?
Hello,

In my C# asp.net 2.0 application, I have a webform with a button server
control on it. The webform, like most others in the site, subscribes to
a master page. I have determined that the button always renders with an
id of "ct100_ContentPlaceHolder1_btnContinue" in both the IE and
Firefox browsers.

I created the following javascript code segment to disable it when the
page loads. I have reasons for not wanting to do this with server side
code...

document.all[''ct100_ContentPlaceHolder1_btnContinue''].disabled = true;

Now, when I view this in IE, the button is disabled. But when I view it
in Firefox, it''s not. Also, there are no javascript errors returned by
either browser. Also, I have already updated my browserCaps section in
web.config, if that is relevant.

Why does the button remain enabled when viewing the page with Firefox?



这篇关于使用Javascript禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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