Jquery UI 按钮在刷新时被禁用
几周前我在 jquery 论坛上询问过这个问题,但没有运气,所以我会在这里再试一次:)
我为我正在从事的项目制作了一个简单的小部件,但我遇到了一个奇怪的问题。
通过示例实现来解释它是最简单的。 http://decko.dk/buttontest
页面上有3个按钮。第一个是我的下拉小部件。下一个是常规禁用按钮 (A),最后一个是常规启用按钮 (B)。 如果您随后刷新页面(按 F5 或其他方式),则启用的按钮现在会神秘地禁用。 我不知道为什么会发生这种情况,但是如果按钮 A 一开始就没有被禁用,则刷新时按钮 B 将不会被禁用。另外,如果我在小部件代码中删除对 insertAfter 的调用,则该按钮将不会被禁用。 谁能解释为什么会出现这种奇怪的行为?
顺便说一句,我只能在 Firefox 中重现这一点。
I asked about this on the jquery forum a few weeks ago without luck, so I will try again here :)
I've made a simple widget for a project I'm working on, but I have encountered an odd problem.
It is easiest to explain it with an example implementation.
http://decko.dk/buttontest
On the page there are 3 button. The first one is my drop down widget. The next one is a regular disabled button (A) and the last one a regular enabled button (B).
If you then refresh the page (press F5 or whatever) the enabled button is mysteriously now disabled.
I have no clue why this happens, but if button A is not disabled to begin with, button B will not be disabled when refreshing. Also, if I remove the call to insertAfter in my widget-code, the button will not be disabled.
Can anyone shed light on why this strange behavior occurs?
By the way, I have only been able to reproduce this in Firefox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我相信这是 Firefox 记住表单字段/控件值和状态的错误:
这里有两个问题:
测试用例可以简化为仅动态添加
I believe this is a bug in how Firefox remembers form field/control values and states:
<button>
elements in the document, and<button id="button_a">
is disabled. (When the jQuery UI styled button is enabled or disabled, it sets the underlying element to the same state.)<button>
is disabled.<button>
, but since no script has been run, the second button is<button id="button_b">
.<button id="button_b">
, it sees that it is disabled and continues to style it as disabled.There are two issues here:
The test case can simplify down to just adding a
<button>
element dynamically and disabling<button id="button_a">
, no jQuery / jQuery UI necessary:我也遇到了这个问题,并发现这是由于 Firefox 中的愚蠢行为,我的修复如下:
之前:
之后:
I've been getting this problem also and worked out it was down to silly behaviour in firefox, my fix was as so:
before:
after:
将
Expires
HTTP 标头设置为过去的日期,解决了我在 Firefox 6.0 中的问题。Setting the
Expires
HTTP header to a date in the past, solved the problem for me in Firefox 6.0.这是我发现在所有浏览器中都非常有效的解决方案...
我为每个按钮(可以禁用)提供一个“js_submit”类,
然后在触发的 pagehide 事件上重新启用具有“js_submit”类的所有已禁用按钮页面已卸载。
我将事件分配包装在 try catch 中,以防止不支持此事件的浏览器(例如 IE)抛出错误。
这是代码:
Here is the solution I found works really well in all browsers...
I give each button (that can be disabled) a class 'js_submit'
I then re-enable any disabled buttons with class 'js_submit' on the pagehide event that fires when a page is unloaded.
I wrap the event assignment inside a try catch to prevent browsers that don't support this event from throwing an error (such as IE).
Here is the code:
就我而言,这是一个 Bootstrap bug
相反,它应该是
In my case it was a Bootstrap bug
Instead it should have been