CDATA是什么意思 [英] What is the meaning of CDATA
问题描述
大师,
我是自学成才的.你有很多开明的人称呼基本,我对此一无所知.
I am self taught. There's a lot of what you enlightened ones call basic I know nothing about.
阅读此 jQuery教程时,我注意到此标记(由于缺少更好的单词):"CDATA",如下所示(从顶部开始的第三行):
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>
CDATA是什么意思?是否有类似于CDATA的标签?
What is the meaning of CDATA? Are there tags similar to CDATA?
推荐答案
使用<![CDATA[
,您可以嵌入XML(和XHTML)文档中的JS ,而无需替换特殊XML字符<,>
,&
等的<
,>
,&
等a>,以防止XML语法格式错误以及出现.但是,一般建议将JS代码放在自己的.js
文件中,然后由<script src>
包含.
With <![CDATA[
you can embed JS in XML (and XHTML) documents without the need to replace special XML characters like <
, >
, &
, etc by XML entities <
, >
, &
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>
.
在纯HTML文档中不需要<![CDATA[
.除非您使用诸如 Facelets (对于JSF)或ASP.NET MVC之类的基于XML的视图技术进行开发,否则绝对没有需要将您的HTML声明为 XHTML .只需<!DOCTYPE html>
就足够了
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
这篇关于CDATA是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!