how to stop changing the code?

社会主义新天地 提交于 2019-12-25 05:30:57

问题


Good day.

I have this code:

<div class="align-center">
 <a href="#" class="client">
  <div><img src="./client0.png" alt="" /></div>
  <p class="italic comm"> Test Test Test Test</p>
</a>
</div>

I paste this code in a textarea ckeditor, but after pressing the tab "source" and back to view page I get changed code:

<div class="align-center">
 <div>
 <a class="client" href="#"><img alt="" src="./client0.png" /></a>
 </div>    
 <p class="italic comm"><a class="client" href="#"> Test Test Test Test</a></p>
</div>

Please tell me how to stop changing the code?


回答1:


The reason for such behavior is that your markup is invalid.

HTML 4.01 specification (also xHTML 2.0) doesn't allow block elements like <div> inside <a> (see this answer). CKEditor follows those specs so, of course, it also finds your code invalid. Still, CKEditor's parser tries to fix your HTML and the result is what you call "changed code".

Your code could be valid in HTML5 though. CKEditor doesn't support HTML5 DTD yet because it's complex and dynamic as opposed to HTML 4.01 (xHTML 2.0).

At the moment, the only solution is to change your code.



来源:https://stackoverflow.com/questions/17016828/how-to-stop-changing-the-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!