删除禁用的表单字段的禁用属性onClick [英] Remove disabled attribute onClick of disabled form field

查看:102
本文介绍了删除禁用的表单字段的禁用属性onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单字段,开始是禁用的,并且具有onClick来启用它. onClick不会触发(至少在FF中),也不会触发简单的alert(1);.

I have a form field that starts out disabled and has an onClick to enable it. The onClick doesn't fire (at least in FF) nor does a simple alert(1);.

hacky版本将在其位置显示一个伪造的表单字段,使其看起来像已禁用(呈灰色样式)和onClick,然后将其隐藏并显示正确的字段,但这很丑陋.

The hacky version is to show a fake form field in its place that "looks" like it's disabled (grayed out style) and onClick, hide it and show the correct field enabled, but that's ugly.

示例代码

这有效:

<input type="text" id="date_end" value="blah" onClick="this.disabled=true;">

这有效:

<label for="date_end_off" onClick="document.getElementById('date_end').disabled=false">Test</label>
<input type="text" id="date_end" value="blah" onClick="alert(1);" disabled>

此操作失败:

<input type="text" id="date_end" value="blah" onClick="alert(1);" disabled>

此操作失败:

<input type="text" id="date_end" value="blah" onClick="document.getElementById('date_end').disabled=false" disabled>

推荐答案

我在另一个论坛上遇到了这个话题,所以我想我必须以不同的方式去做.

I came across this thread in another forum so I assume I'll have to go about it a different way.

http://www.webdeveloper.com/forum/showthread.php? t = 186057

Firefox,也许还有其他浏览器, 在表单字段上禁用DOM事件 被禁用.任何事件始于 禁用表单字段是完全 已取消且不会向上传播 DOM树.如果我错了,请纠正我,但是 如果单击禁用按钮, 事件的来源是 禁用按钮,而点击事件为 完全消灭.浏览器 根本不知道按钮有 点击,也没有通过点击 事件开启.就好像您在点击 在网页上的黑洞中.

Firefox, and perhaps other browsers, disable DOM events on form fields that are disabled. Any event that starts at the disabled form field is completely canceled and does not propagate up the DOM tree. Correct me if I'm wrong, but if you click on the disabled button, the source of the event is the disabled button and the click event is completely wiped out. The browser literally doesn't know the button got clicked, nor does it pass the click event on. It's as if you are clicking on a black hole on the web page.

解决方法:

  1. 设置日期字段的样式,使其看起来像 他们被禁用了.
  2. 创建一个隐藏的"use_date"表单字段 用一个位值来确定 是否在处理期间使用日期字段.
  3. 将新功能添加到日期字段的onClick上 更改样式类以显示 启用并设置"use_date"值 到1.
  1. Style the date fields to look as if they are disabled.
  2. Make a hidden "use_date" form field with a bit value to determine whether to use the date fields during processing.
  3. Add new function to onClick of the date fields which will change the style class to appear enabled and set the "use_date" value to 1.

这篇关于删除禁用的表单字段的禁用属性onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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