JQuery UI编码噩梦 [英] JQuery UI encoding nightmare
问题描述
我希望能够将任何字符串传递给JQuery UI中的按钮文本。
I want to be able to pass any string to the buttons text in JQuery UI.
假设我有这个字符串:
Ajouter L'amie a la listeamies
Ajouter L'amie a la liste "amies"
实际传递此文本而不会导致大量JavaScript错误的唯一方法是使用HTML编码它。
The only way to actually pass this text without causing a massive JavaScript error is by HTML-encoding it.
registerhtml.dialog({
modal: true,
title: 'My Dialog Title',
resizable: false,
buttons: [
{
text: 'Ajouter L'amie a la liste "amies"',
click: function(){
// Do something important
$(this).dialog('close');
}
},
{
text: 'Cancel',
click: function() {
$(this).dialog('close');
}
}
]
});
但我没有在按钮中获得任何人类可读文本。只有相同的编码文本。
But I'm no getting any Human-Readable text in the button. Only the same encoded text.
有没有快速解决此问题的方法?也许我在按钮对象中缺少一个选项。
Is there a quick way to solve this issue? Maybe there's an option that I'm missing in the button object.
或者我应该戴上手套,打电话给护士并在JQuery-ui.js文件中开始手术?
Or should I put my gloves, call a nurse and start surgery in the JQuery-ui.js file?
推荐答案
为了能够使用htmlentities,在将字符串插入按钮时,你必须使用 html
方法,如 text
将逐字插入文本,而不对实体进行编码:
To be able to use htmlentities, you'll have to use the html
method when inserting the strings into the buttons, as text
will literally insert the text without doing encoding of entities :
registerhtml.dialog({
modal: true,
title: 'My Dialog Title',
resizable: false,
buttons: [
{
html: 'Ajouter L'amie a la liste "amies"',
click: function(){
// Do something important
$(this).dialog('close');
}
},
{
html: 'Cancel',
click: function() {
$(this).dialog('close');
}
}
]
});
这篇关于JQuery UI编码噩梦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!