简体   繁体   English

格式化JavaScript标记的正确方法是什么?

[英]What is the proper way to format a JavaScript tag?

Having developed web apps since 1996 I often find new ways of doing old things. 自1996年开发Web应用程序后,我经常会找到做旧事的新方法。 So I was wondering what is the proper JavaScript tag to use on new development? 所以我想知道在新开发中使用什么是正确的JavaScript标记?

Currently I use something like this for XHTML 目前我使用类似的东西用于XHTML

<script type="text/javascript">
/* <![CDATA[ */

/* ]]> */
</script> 

I have read somewhere that this may cause problem with older browsers. 我在某处读过这可能会导致旧浏览器出现问题。

But use to use the following: 但是使用以下内容:

<script language="javascript">

<script type="text/javascript">

<script language="javascript" type="text/javascript">

What is the prefered method and why? 什么是首选方法,为什么?

Checkout what Crockford has to say. 看看克罗克福德有什么要说的。 In summary: 综上所述:

<script src="url"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM