问题
I want to add <span>
tag inside of an <a>
tag in the CKEditor source:
<a href="http://google.com"><span>Link here</span></a>
But when I add the HTML in CKEditor in source mode, it converts it to:
<a href="http://google.com">Link Here</a>
How can I allow HTML tags inside a href
?
回答1:
Do u really need to put the <span>
tags in there? Isn't it better to add a class to your link and edit it(the css I guess u want) from there.
What u can do:
Try doing it the other way:
<span><a href="http://google.com">Link here</a></span>
Open your html file in Notepad/PSpad or anything that always shows you the rare source code and try to write it there - shouldn't be a problem.
As I already wrote up - if u want that span there for editing css of the link text - use class in your link and edit css values. Example:
<a href="http://google.com" class="myLink">Link Here</a>
and in css:.myLink { ...your custom setting... }
If you could tell us for what you need the span tags there it would help us answering you :)
P.S.: I'm sorry that I'm not answering about the editor you are using. I just think you might want to try other editors that don't disable stuff u usually can do when writing the code.
回答2:
This <span>
is removed by Advanced Content Filter. Apparently (and this is not surprising) none of features enabled in your editor allows bare spans (which are crappy non-semantic HTML), so they are simply removed.
I advice you not to use such messy HTML, because CKEditor will at some point break your <a>+<span>
doublets because it does not know that they should be edited together.
However, if you need to use them, then check these options: config.allowedContent or config.extraAllowedContent. First one allows to completely disable Advanced Content Filter.
回答3:
Use extraAllowedContent filter:
CKEDITOR.replace('ckeditor', {
extraAllowedContent: 'a span',
});
来源:https://stackoverflow.com/questions/16300990/ckeditor-allow-span-inside-a-tag