在我的文本区域中解码特殊字符(使用就地编辑 jQuery 插件)
我正在尝试使用 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>
如何显示正确的字符?
I'm trying tu use Jeditable to edit inline some content put in textareas.
So, I call the script files:
<script src="js/jquery.jeditable.js"></script>
<script src="js/jquery.jeditable.autogrow.js"></script>
<script src="js/jquery.autogrow.js"></script>
Then I have a function that should send data to the server (I kept the example URL).
This fonction creates a textarea and permits the edition:
$(".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
}
});
Then, I have the data to edit thant contains HTML tags because I have to store them:
$data = '<div style="color:red">Foo Bar</div>';
echo '<div class="autogrow">'.htmlentities($data).'</div>';
The "echo" displays the "$data" content perfectly with the tags, but when I want to edit inline the DIV, a textarea is created and the following data is displayed in that textarea:
<div style="color:red">Foo Bar<div>
instead of:
<div style="color:red">Foo Bar</div>
How can I display the right characters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:我没有意识到这个问题是在 2 个多月前提出的 - 抱歉,
当您将文本放入文本区域时,您是否尝试过使用
html_entity_decode()
函数?htmlentities()
函数会将<
等内容更改为<
,而html_entity_decode()
应该将<
更改为<
基本上,textarea 不会格式化您的 HTML 标签,因此您需要自己转换它们。
不过我已经有一段时间没有使用PHP了,所以我不太记得了。
Edit: I didn't realise this question was asked over 2 months ago - Sorry
Have you tried using the
html_entity_decode()
function when you put the text into a text area?The
htmlentities()
function will change things like<
into<
, whilehtml_entity_decode()
should change<
into<
Basically a textarea will not format your HTML tags so you need to convert them yourself.
However it has been a while since I used PHP so I can't remember too well.
只需编辑此文件 js/jquery.jeditable.js
转到第 #:398 $.editable{} 函数,并添加以下代码行,
谢谢
Simply edit this file js/jquery.jeditable.js
go to line #:398 $.editable{} function, and add the line as in below code
Thanks