使用 ASP.NET CheckBox 控件时无法在 IE 中启用复选框
我有一个 HTML 表单,其中有两个禁用的复选框和带有 onclick
事件的图像,该事件需要显示弹出窗口并启用复选框:
<input id="chk1" type="checkbox" disabled="disabled" />
<input id="chk2" type="checkbox" disabled="disabled" />
<img src="..." onclick="window.open('...'); document.getElementById('chk1').disabled=false;document.getElementById('chk2').disabled=false" />
但它不起作用。弹出窗口打开,但复选框从未启用。
我没有尝试使用 disabled=false
而不是 removeAttribute("disabled")
但没有成功。我还将 window.open
放置为 onclick
中的最后一个语句,没有任何更改。
jQuery 还不在这个项目中,所以我无法使用它。我做错了什么?
编辑:
当我发布此内容时,我没有透露 input
标记是由 ASP.NET 呈现的。通过测试我们发现使用
和 之间存在差异这会影响
disabled
属性在 IE 和 FF 中的行为方式。
我一直认为最终的输出是相同的,但显然不是,尽管我无法发现差异。当使用 CheckBox 对象时,如上所示的渲染代码可以在 FF 中工作,但不能在 IE 中工作,但在使用 HtmlInputCheckBox 对象时,可以在两者中工作。
(我还应该指出,getElementById
调用实际上是使用各个元素的 ASP.NET ClientID 属性。)
那么我现在的问题是,为什么会出现这种情况?为什么使用 HtmlInputCheckBox 对象时启用/禁用功能在 IE 和 FF 中都有效,但对于 CheckBox 对象却不起作用?
I have an HTML form with two disabled checkboxes and and image with an onclick
event that needs to show a popup and enable the checkboxes:
<input id="chk1" type="checkbox" disabled="disabled" />
<input id="chk2" type="checkbox" disabled="disabled" />
<img src="..." onclick="window.open('...'); document.getElementById('chk1').disabled=false;document.getElementById('chk2').disabled=false" />
except it doesn't work. The popup window opens, but the checkboxes never enable.
Instead of disabled=false
I've tried removeAttribute("disabled")
with no luck. I also placed the window.open
as the last statement in the onclick
with no change.
jQuery is not in this project (yet) so I can't use it. What am I doing wrong?
Edit:
When I posted this, I failed to disclose the input
tags are being rendered by ASP.NET. Through testing we've discovered there's a difference between using <asp:CheckBox />
and <input type="checkbox" runat="server" />
that affects how the disabled
property behaves in IE and FF.
I've been under the impression that the final output would be the same, but apparently not, though I haven't been able to spot the difference. The rendered code as represented above works in FF but not IE when using an CheckBox object, but works in both when using an HtmlInputCheckBox object.
(I should also point out that the getElementById
calls are actually using the ASP.NET ClientID property for the respective elements.)
My question now, then, is why is this the case? Why does the enable/disable functionality work in both IE and FF when using a HtmlInputCheckBox object but not for a CheckBox object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试用这个,
Try with this,
我刚刚找到了解决方案。这对我有用!
I just found the solution. It works for me !
首先检查您的网络,其次这是一个链接,这是一个可供您使用的好功能
复选框禁用/启用 JS 功能
First check your network, second here is a link, a nice function to use for you
Checkbox Disable/Enable JS Function
要启用复选框,我通常应用以下两项:
一些浏览器喜欢 DOM 节点属性,其他浏览器希望调整 attr。
如果你说你正在做的事情不起作用,我很抱歉——我不太清楚你在说什么。
To enable a checkbox, I generally apply both of the following:
Some browsers like the DOM node property, others want the attr adjusted.
I apologize if this is what you said you were doing which was not working--I wasn't quite clear on what you were saying.
尝试这样做:
Try doing this:
事实上,您可以执行相反的操作来启用复选框。试试这些...
In fact, you do the oppisite to enable your checkbox. Try these...