最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - What is the proper way to format a JavaScript tag? - Stack Overflow

programmeradmin1浏览0评论

Having developed web apps since 1996 I often find new ways of doing old things. So I was wondering what is the proper JavaScript tag to use on new development?

Currently I use something like this for 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?

Having developed web apps since 1996 I often find new ways of doing old things. So I was wondering what is the proper JavaScript tag to use on new development?

Currently I use something like this for 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?

Share Improve this question asked Feb 21, 2010 at 19:40 Todd MosesTodd Moses 11k11 gold badges49 silver badges65 bronze badges 2
  • I always wonder what CDATA is actually for? – Layke Commented Feb 21, 2010 at 19:52
  • 1 The CDATA is to escape xml characters like < and > in the JavaScript. It's needed for xhtml if it is processed by a strict xml parser. – David Hogue Commented Feb 21, 2010 at 19:58
Add a ment  | 

1 Answer 1

Reset to default 11

Checkout what Crockford has to say. In summary:

<script src="url"></script>
发布评论

评论列表(0)

  1. 暂无评论