jEditable将输入中的HTML转换为文本 [英] jEditable Convert HTML in Input to Text

查看:118
本文介绍了jEditable将输入中的HTML转换为文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery插件jEditable.我遇到的问题是,在触发jEditable事件后,我希望任何可编辑的内容都可以显示文本而不是html.

例如,如果我有一个元素<span class="editable">Jack & Jill</span>,则单击它会得到Jack &amp; Jill,但是我想要的是Jack & Jill作为输入中的值,这样用户就不会看到HTML. /p>

我必须对数据设置做些什么[也许是value.replace();或者其他的东西].现在,我只需要它返回值.

CODE

$('.editable').each(function() {
      $(this).editable('url', {
                data: function(value, settings) {
                      var retval = value;
                      return retval;
                }

      });
});

解决方案

使用php渲染页面时,看起来您正在使用htmlspecialchars()或类似的东西来翻译&插入等效于&amp;的html实体.

因此,当您对其进行编辑时,与其从页面上的项目中加载信息,不如从ajax调用中将其加载到服务器(它将返回实际的html,而无需通过htmlspecialchars()或其他任何方式运行)别的).

Jeditable为此提供了一个不错的选择,因此请尝试以下操作:

$('.editable').each(function() {
      $(this).editable('url', {
                loadurl  : 'http://www.example.com/returnUntouchedhtml.php',
                data: function(value, settings) {
                      var retval = value;
                      return retval;
                }

      });

});

您可以在此页面上找到更多示例/信息: http://www.appelsiini.net/projects /jeditable

Using jQuery plugin jEditable. Problem I'm having is that I want whatever is editable to display the text instead of the html after I trigger the jEditable event.

For example if I have an element <span class="editable">Jack & Jill</span>, when I click it, I get Jack &amp; Jill, but what I want is Jack & Jill as my value in the input so that the user doesn't see HTML.

There must be something I can do with the data setting [perhaps a value.replace(); or something]. Right now I just have it returning the the value.

CODE

$('.editable').each(function() {
      $(this).editable('url', {
                data: function(value, settings) {
                      var retval = value;
                      return retval;
                }

      });
});

解决方案

When you render the page with php, it looks like you are using htmlspecialchars() or similar to translate & into its html entity equivalent &amp;.

So when you edit it, instead of loading the information from the item on the page, you need to load it from an ajax call to your server (which will return the actual html, without running it through htmlspecialchars() or anything else).

Jeditable gives you a nice option for this, so try something like:

$('.editable').each(function() {
      $(this).editable('url', {
                loadurl  : 'http://www.example.com/returnUntouchedhtml.php',
                data: function(value, settings) {
                      var retval = value;
                      return retval;
                }

      });

});

You can find more examples/information on this page: http://www.appelsiini.net/projects/jeditable

这篇关于jEditable将输入中的HTML转换为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆