Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

jquery - What is the meaning of CDATA

Gurus,

I am self taught. There's a lot of what you enlightened ones call basic I know nothing about.

Reading this jQuery Tutorial, I noticed this tag (for lack of better word): "CDATA" as shown here (third line from the top):

<script src="http://jquery.com/src/jquery-latest.js"></script>
<script> 
//<![CDATA[    
$(document).ready(function(){
$(".article .thebody").hide();
$("#container .article ul")
       .prepend("<li class='readbody'><a href='' title='Read the article'>Read Body</a></li>");

$(".actions li.readbody a").click(function(event){
$(this).parents("ul").prev(".thebody").toggle();
event.preventDefault();
     });
   });
//]]></script>

What is the meaning of CDATA? Are there tags similar to CDATA?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With <![CDATA[ you can embed JS in XML (and XHTML) documents without the need to replace special XML characters like <, >, &, etc by XML entities &lt;, &gt;, &amp; etc to prevent that the XML syntax get malformed and that you get errors like The entity name must immediately follow the '&' in the entity reference. The general recommendation is however to put JS code in its own .js file which you then include by a <script src>.

The <![CDATA[ is not needed in plain HTML documents. Unless you're developing with a XML based view technology like Facelets (for JSF) or ASP.NET MVC, there's absolutely no need to declare your HTML as XHTML. Just a <!DOCTYPE html> would suffice


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...