Tinymce - 插入html代码 [英] Tinymce - insert html code

查看:549
本文介绍了Tinymce - 插入html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人能够帮助我解决这个问题,我将不胜感激,我一直试图解决它几天,但没有成功。
我制作了自定义按钮,用于将图片插入代码中,这里是文本版本:

 < a href =的JavaScript :; onmousedown =tinyMCE.execCommand('mceInsertContent',false,'< img alt = $ img_title src = $ link / img / sadrzaj / $ file \>');>插入图像<一个> 

问题是我不允许使用引号,所以我必须使用alt = Some_value和引号被自动添加。
问题出现在我用空格输入值时:alt =某些值,然后只有Some被输入,而空白后的所有内容都被忽略。对于src属性是可以的,因为它不能包含空格,但对于图像描述来说非常有用。
我可以格式化字符串,而不是空格,但这不是解决方案。



请提供任何帮助?

解决方案

在要包含的引号之前添加反斜杠( \ )。

 < a href =javascript :; 
onmousedown =tinyMCE.execCommand('mceInsertContent',false,'< br>
< img alt = \'$ img_title \'src = \\''link / img / sadrzaj / $ file \\'/>');>插入图片< / a>

这将允许您在脚本和引号中包含脚本和引号,而不会打碎您。



反斜杠对代码说:不要停在这里,这个引号并不代表代码行结束,只要将它包含在显示输出中,谢谢。



请注意,您必须在 IMG 附近使用单引号(' (另一件事:在XHTML中,自我关闭标签,如 IMG ,你使用斜杠( / )而不是反斜杠。)


I would appreciate if there is someone who can help me solve this problem, I've been trying to resolve it for few days, but with no success. I made custom button that inserts image into code, and here is textual version:

<a href="javascript:;" onmousedown="tinyMCE.execCommand('mceInsertContent',false,'<br><img alt=$img_title src=$link/img/sadrzaj/$file\>');">Insert Image</a>

Problem is that I'm not allowed to use quotes so I have to use alt=Some_value and quotes are added automaticly. Problem comes when i enter value with space: alt=Some value and then only "Some" is entered while everything after whitespace is ignored. For src attribute it's ok because it cant contain whitespaces, but for image description it would be very useful. I can format string and put _ instead of whitespace but that's not solution.

Any help, please?

解决方案

Add a backslash (\) before the quotes you want to include.

<a href="javascript:;" 
  onmousedown="tinyMCE.execCommand('mceInsertContent',false,'<br>
  <img alt=\'$img_title\' src=\'$link/img/sadrzaj/$file\' />');">Insert Image</a>

This will allow you to include the script and the quotes without it breaking on you.

The backslash just says to the code, "Don't stop here, this quote does not signal the end of the code line. Just include this in the display output. Thanks."

Note that you will have to use single quotes (') around the IMG attributes.

(Another thing: In XHTML, when self-closing a tag like IMG, you use the slash (/) and not the backslash.)

这篇关于Tinymce - 插入html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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