带有jQuery 1.8的jQuery UI 1.8.22在对话框按钮中没有文本 [英] jQuery UI 1.8.22 with jQuery 1.8 doesn't have text in dialog buttons
问题描述
我去检查了最近发布的jQuery 1.8(稳定版)是否与我当前正在开发的项目兼容,令我惊讶的是,这是我看到的第一件事:
I went to check if the recently released jQuery 1.8 (stable) would be compatible with my current project in development, and to my surprise this is the first thing I saw:
令我惊讶的是,我已经升级到jQuery UI 1.8.22,根据其
It is a surprise to me as I had already upgraded to jQuery UI 1.8.22, which according to its release post, is compatible with jQuery 1.8.
回调函数是根据调用的,但是按钮没有textNode
,就像在DOM检查器中可以看到的那样:
The callback functions are called according, but the buttons have no textNode
s as one can see in a DOM inspector:
到目前为止,我找到的解决方案是:
The solutions which I've found so far are either:
- 降级回jQuery 1.7.2(不过我想在页面中使用最新的jQuery版本)
- 升级到jQuery UI 1.9.0pre(不稳定)
- 使用
open
处理程序或手动编辑对话框的HTML以包含我想要的文本.似乎在其源代码中出现了许多不必要的麻烦.
- Downgrade back to jQuery 1.7.2 (I would like to use the latest jQuery version in my page though)
- Upgrade to jQuery UI 1.9.0pre (it's not stable)
- Use an
open
handler or manually edit the HTML of the dialog to include my desired text. Seems like a lot of unneeded hassle for a bug in their source.
我错过了什么吗?或者这是一个实际的错误?
这是我用于演示的小提琴:
Here's the fiddle which I used for the demo:
以及供将来参考的代码:
And the code for future reference:
HTML :
<div id="foo" title="Dialog title">Dialog text</div>
JS :
$('#foo').dialog({
buttons: {
Yes: function() { $(this).dialog('close'); },
No: function() { $(this).dialog('close'); }
}
});
推荐答案
这是 BugTracker票证.
一个更简单的解决方案是在包含jQuery库后使用此代码段:
A much simpler solution is to use this snippet after including the jQuery library:
if ( $.attrFn ) { $.attrFn.text = true; }
jsFiddle
当发布jQuery UI 1.8.23时,应解决此问题.在BugTracker票证页面上归功于scott.gonzalez.
jsFiddle
This issue should be fixed when jQuery UI 1.8.23 is released. Credits to scott.gonzalez from the BugTracker ticket page.
编辑:此问题已在 UI 1.8.23 .
我的旧解决方案:
(如果您遇到上述问题,请使用它)
My old solution:
(use it if you have problems with the one above)
我已针对此问题进行了临时修复(直到发布了新的UI或核心稳定版本).
I've made a temporary fix for this issue (until a new stable version of either UI or core is release).
jQuery 1.8与jQuery UI 1.8.22交互存在一个错误,该错误将文本存储在父button
的text
属性中,而不是在span.ui-button-text
内部创建textNode
:
There's a bug with jQuery 1.8 interacting with jQuery UI 1.8.22 which stores the text in the parent button
's text
attribute instead of creating a textNode
inside the span.ui-button-text
:
初始化jQuery UI dialog
或具有此UI按钮错误的任何其他接口后,请使用以下代码段:
Use this snippet after initializing jQuery UI dialog
s or any other interface which has this UI button bug:
//iterate through all UI button text spans in the document
$('.ui-button-text').each(function() {
var $this = $(this);
if ($this.text() == '') //if it has no text (bugged)
$this.text($this.parent().attr('text')); //sets the text which was passed
});
jsFiddle
该脚本会在执行任何操作之前检查UI按钮是否没有文本,因此即使升级到将来的非bug版本的core/UI,即使您忘记了该按钮,也可以将它保留在那里.
jsFiddle
The script checks if the UI button has no text before doing anything, so it's harmless to keep even if you forget it there when upgrading to future non-bugged versions of core/UI.
如果您对此错误有更好的解决方案或信息,我们将很乐意接受. =]
If you have a better solution or information on this bug I'll glad accept it. =]
请注意,如果您迫不及待想要发布稳定版本并且仍想使用最新的稳定版本,则可以降级到jQuery 1.7.2或使用UI 1.9.0的预发布版本.
Note that you can downgrade to jQuery 1.7.2 or use a pre-release of UI 1.9.0 as mentioned in the question if you can't wait for a stable release and still want to use the latest stable versions.
这篇关于带有jQuery 1.8的jQuery UI 1.8.22在对话框按钮中没有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!