需要 jquery unformjs 中的帮助选择菜单 '&'字符编码
我正在使用uniformjs表单控件,除了列表菜单之外,这些控件都可以工作。当我添加“&”时列表菜单中的符号 (&),它可以正确呈现,但是当我将值更改为不同的值并再次选择具有 & 的值时,问题就出现了。它呈现为 &
而不是 '&' 的符号列表菜单中的符号。
<select>
<option>Through & Google</option>
<option>Through Twitter</option>
<option>Other…</option>
<option><Hi></option>
</select>
有人可以告诉我什么是问题..
I am using uniformjs form controls which are working except the listmenu. When i add '&' symbol (&) inthe list menu, it renders correctly, but problem is coming when i change the value to different value and select again the value which has & symbol it renders as &
instead '&' symbol in the list menu.
<select>
<option>Through & Google</option>
<option>Through Twitter</option>
<option>Other…</option>
<option><Hi></option>
</select>
can someone tell me what is the problem..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Didler 的说法,为什么不稍微修改一下uniformjs呢?
我最近遇到了同样的情况,感谢 Didler 指出了确切的线路,这节省了我大量的时间来找到这个地方。
就我而言,我有一个值由特殊字符组成的选择,例如:
因此我将第 185 行中的代码修改为:
这解决了渲染值时其形状正确的问题。
在op的场景中,我不确定您使用的是哪种服务器端语言,但肯定有一种方法可以在生成html页面之前转义选项内的文本,这样就没有
&
在你的html中,但在字符本身。我使用的是 Java,因此我可以简单地使用 JSTL
将值放入选项标记中。According to Didler, why not modify the uniformjs a little bit?
I have met the same scenario recently, and thanks Didler to point out the exact line which saves me heaps of time to locate the place.
In my case, I have a select with value consists of special characters, such as:
So that I modify the code in line 185 to:
which solves the problem that when render the value it is in a correct shape.
In op's scenario, I'm not sure which server side language you are using, but definitely there is a way to escape the text within option before generating the html page so that there is no
&
in your html but the character itself.I'm using Java so that I can simply use JSTL
<c:out value="${******}"/>
to put the value in the option tag.有一个拉取请求 (130) 更新了 4 行代码(第 173 行, 185、212 和 569),因此它们不使用
.html()
,而是使用.text()
。我看到的两个后来的拉取请求似乎没有更新所有 4 行。如果您也想更新缩小版本,可以搜索这两个片段:
l.html(n.html()
(x1 - 更改“html”的第二个实例): selected").html(
(x3 - 仅更改“html”的实例)There's a pull request (130) that updates 4 lines of code (lines 173, 185, 212, and 569) so that instead of using
.html()
they use.text()
. The two later pull requests I saw don't seem to update all 4 lines.If you wish to update the minified version as well, you can search for these two snippets:
l.html(n.html()
(x1 - change second instance of 'html'):selected").html(
(x3 - change only instance of 'html')我认为问题可能来自这一行(源 - 行185):
如果您有以下 html:
插件将内容获取为 html 执行
elem.find(":selected").html()
两个选项元素在获取 html 时都会返回此值:
One &两个
特殊字符由 html 实体表示(在我们的示例中
&
表示&
)然后插件将此结果应用为文本 使用
spanTag.text();
因此 html 实体不会被解析(
&
显示为&
)这个fiddle 说明了这一点。
我认为除了不使用
&
等特殊字符之外没有其他解决方案...I think the problem might come from this line (source - line 185):
If you have the following html:
The plugin gets the content as html doing
elem.find(":selected").html()
Both option element will return this value when getting html:
One & Two
Special characters are represented by html entities (
&
for&
in our example)and then plugin applies this result as text using
spanTag.text(<html>);
So html entities do not get parsed (
&
is displayed as&
)This fiddle illustrates it.
I don't think there is a solution to that except to not use special characters like
&
...