2

我正在尝试使用 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 时,会创建一个 textarea 并在该 textarea 中显示以下数据:

&lt;div style="color:red"&gt;Foo Bar&lt;div&gt;

代替:

<div style="color:red">Foo Bar</div>

如何显示正确的字符?

4

2 回答 2

0

编辑:我没有意识到这个问题是在 2 个多月前被问到的 - 抱歉

html_entity_decode()将文本放入文本区域时,您是否尝试过使用该功能?

htmlentities()函数将更改为<into之类的内容&lt;,而html_entity_decode()应该更改&lt;<

基本上 textarea 不会格式化您的 HTML 标签,因此您需要自己转换它们。

但是,自从我使用 PHP 以来已经有一段时间了,所以我记不太清了。

于 2010-10-07T14:46:38.963 回答
-1

只需编辑此文件 js/jquery.jeditable.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);
                },

谢谢

于 2015-03-10T09:43:29.543 回答