在我的文本区域中解码特殊字符(使用就地编辑 jQuery 插件)
-
27-09-2020 - |
题
我正在尝试使用 Jeditable 编辑内嵌文本区域中的一些内容。因此,我将脚本文件称为:
<script src="js/jquery.jeditable.js"></script>
<script src="js/jquery.jeditable.autogrow.js"></script>
<script src="js/jquery.autogrow.js"></script>
然后我有一个函数应该将数据发送到服务器(我保留了示例 URL)。此函数创建一个文本区域并允许编辑:
$(".autogrow").editable("http://www.appelsiini.net/projects/jeditable/php/save.php", {
indicator : "<img src='img/indicator.gif'>",
type : "autogrow",
submit : 'OK',
cancel : 'cancel',
tooltip : "Click to edit...",
onblur : "ignore",
event : "dblclick",
autogrow : {
lineHeight : 16,
minHeight : 32
}
});
然后,我需要编辑包含 HTML 标签的数据,因为我必须存储它们:
$data = '<div style="color:red">Foo Bar</div>';
echo '<div class="autogrow">'.htmlentities($data).'</div>';
“echo”与标签完美地显示“$data”内容,但是当我想编辑内联 DIV 时,会创建一个文本区域,并在该文本区域中显示以下数据:
<div style="color:red">Foo Bar<div>
代替:
<div style="color:red">Foo Bar</div>
如何才能显示正确的字符?
解决方案
编辑: 我没有意识到这个问题是在 2 个多月前提出的 - 抱歉
您是否尝试过使用 html_entity_decode()
将文本放入文本区域时的函数?
这 htmlentities()
函数会改变诸如 <
进入 <
, , 尽管 html_entity_decode()
应改变 <
进入 <
基本上,文本区域不会格式化您的 HTML 标签,因此您需要自己转换它们。
不过我已经有一段时间没有使用PHP了,所以我不太记得了。
其他提示
简单地编辑此文件js / jquery.jeditaity.js
转到#:398 $ .Editable {}函数,并将行添加如下代码
$.editable = {
types: {
defaults: {
element : function(settings, original) {
var input = $('<input type="hidden"></input>');
$(this).append(input);
return(input);
},
content : function(string, settings, original) {
string = $('<div/>').html(string).text(); // <--- Add this line
$(':input:first', this).val(string);
},
.
感谢
不隶属于 StackOverflow