jQuery UI按钮在刷新时被禁用 [英] Jquery UI button gets disabled on refresh
问题描述
几周前,我在jquery论坛上问了这个问题,但是没有运气,所以我将在这里再次尝试:)
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.
最容易用示例实现对其进行解释. http://decko.dk/buttontest
It is easiest to explain it with an example implementation. http://decko.dk/buttontest
页面上有3个按钮.第一个是我的下拉小部件.下一个是常规禁用按钮(A),最后一个是常规启用按钮(B). 如果您随后刷新页面(按F5或其他按钮),则已神秘地禁用了已启用的按钮. 我不知道为什么会发生这种情况,但是如果没有从开始禁用按钮A,则刷新时将不会禁用按钮B.另外,如果我在小部件代码中删除对insertAfter的调用,则不会禁用该按钮. 谁能阐明为什么会发生这种奇怪的行为?
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?
顺便说一句,我只能在Firefox中重现它.
By the way, I have only been able to reproduce this in Firefox.
推荐答案
我相信这是Firefox记住表单字段/控件值和状态的错误:
I believe this is a bug in how Firefox remembers form field/control values and states:
- 在第一页加载后,文档中有三个
<button>
元素,并且<button id="button_a">
被禁用. (启用或禁用jQuery UI样式的按钮时,它会将基础元素设置为相同的状态.) - Firefox记住第二个
<button>
被禁用. - 刷新页面后,在运行任何脚本之前,Firefox会还原表单字段和控件.它禁用了第二个
<button>
,但是由于没有运行脚本,因此第二个按钮是<button id="button_b">
. - 当jQuery UI为
<button id="button_b">
创建样式按钮时,它会发现它已被禁用,并继续将其样式设置为已禁用.
- After the first page load, there are three
<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.) - Firefox remembers that the second
<button>
is disabled. - After a page refresh, before any scripts are run, Firefox restores form fields and controls. It disables the second
<button>
, but since no script has been run, the second button is<button id="button_b">
. - When jQuery UI creates the styled button for
<button id="button_b">
, it sees that it is disabled and continues to style it as disabled.
这里有两个问题:
- Firefox如何记住已禁用的元素.它没有考虑动态元素.我建议为此使用Mozilla修复错误.
- 表单元素在页面刷新后保持禁用状态.我不确定这是否正确,但是有两个 bugzilla 报告.
- How Firefox remembers which elements are disabled. It's not taking into account dynamic elements. I suggest filing a bug with Mozilla for this.
- Form elements stay disabled after a page refresh. I'm not sure if this is the correct behaviour, but there are two bugzilla reports on this.
测试用例可以简化为仅动态添加<button>
元素并禁用<button id="button_a">
,而无需jQuery/jQuery UI:
The test case can simplify down to just adding a <button>
element dynamically and disabling <button id="button_a">
, no jQuery / jQuery UI necessary:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>disabled button test</title>
<script type="text/javascript">
window.onload = function () {
var a = document.getElementById('button_a'),
menu = document.createElement('button');
menu.appendChild(document.createTextNode('Menu'));
document.body.insertBefore(menu, a);
a.disabled = true;
};
</script>
</head>
<body>
<button id="button_a">A</button>
<button id="button_b">B</button>
</body>
</html>
这篇关于jQuery UI按钮在刷新时被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!