什么是格式化JavaScript代码的正确方法? [英] What is the proper way to format a JavaScript tag?

查看:91
本文介绍了什么是格式化JavaScript代码的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从1996年开始开发网络应用程序以后,我经常会发现做旧事物的新方法。所以我想知道在新的开发中使用了什么合适的JavaScript标签?



目前,我对XHTML使用类似的东西

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

/ *]]> * /
< / script>

我在某处读过这可能会导致旧版浏览器出现问题。



但用于使用以下内容:

 < script language =javascript> 

< script type =text / javascript>

< script language =javascripttype =text / javascript>

什么是首选方法?为什么?

解决方案

检查克罗克福德有什么要说的。总结:

 < script src =url>< / script> 


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?

解决方案

Checkout what Crockford has to say. In summary:

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

这篇关于什么是格式化JavaScript代码的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆