【问题标题】:Special characters decoded in my textarea (using an edit in place jQuery plugin)在我的 textarea 中解码的特殊字符(使用就地编辑 jQuery 插件)
【发布时间】:2010-07-22 12:56:34
【问题描述】:

我正在尝试使用 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>

如何显示正确的字符?

【问题讨论】:

    标签: jquery html jeditable edit-in-place


    【解决方案1】:

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

    您是否尝试过在将文本放入文本区域时使用html_entity_decode() 函数?

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

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

    不过我用PHP已经有一段时间了,所以记不太清了。

    【讨论】:

      【解决方案2】:

      只需编辑这个文件 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);
                      },
      

      谢谢

      【讨论】:

        猜你喜欢
        • 2013-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多