<script>中text/javascript和application/javascript两个不同属性的区别

如题。

        我最近在做的一个项目里面遇到一个小问题。就是我写在<script>标签中的javascript语句,在chrome,safari,firefox,IE9.10.11上面都可以正常运行,但是到了IE8以下的浏览器就无法运行了。

         一开始以为是我的语句里面有一些兼容性问题,于是我又单独写了个例子去运行,同样的javascript代码在各个浏览器中都成功运行,可是到了我的项目中就是运行不了。

         偶然之中,我瞥见我的<script>标签是这样子写的:

    

<script type="application/javascript">
//执行语句
</script>
         这是书写的时候Dreamweaver自动补全的。

         但是在我自己运行的例子中我的script标签写的是:

<script type="text/javascript">
//执行语句
</script>
          于是,我将我项目中的标签type属性修改成了text-javascript,然后,然后在IE8一下就可以运行了。

          下面补充一下关于这个属性的一些知识:

           最实用的用法,现在各大浏览器已经都基本上支持了HTML5,HTML5中我们已经可以直接使用<script></script>而不需要制定script标签的type属性了。

           根据内核属性,我们将浏览器分为四类:IE6/7/8/9/10/11,firefox, chrome/safari, opera.

           如果需要在script标签中添加type属性,一般type有下面几种:

           1.text/javascript:这是目前来说次于<script></script>标签的最合适的type属性

           2.application/javascript:这个属性亲测在IE8以下的浏览器中无法被识别。

          3.language="javascript":这个标签是W3C的HTML标准,但是目前已经不再推荐使用。

          4. text/ecmascript:少用

          5. text/jscript:少用

          6.text/vbscript:少用

  

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
With this digital Early Release edition of Programming JavaScript Applications, you get the entire book bundle in its earliest form—the author's raw and unedited content—so you can take advantage of this content long before the book's official release. You'll also receive updates when significant changes are made, as well as the final ebook version., Take your existing JavaScript skills to the next level and learn how to build complete web scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this book, you’ll learn how to write flexible and resilient code that’s easier—not harder—to work with as your code base grows., JavaScript has become one of the most widely used—and essential—programming languages for the Web, on both the client-side and server-side. In the real world, JavaScript applications are fragile, and when you change them things often break. Author Eric Elliott shows you how to add features without creating bugs or negatively impacting the rest of your code during the course of building a large JavaScript application., Early Release content now available:, AMD, Asynchronous Operations, Callbacks, Promises and Deferreds, Code Quality, Function Polymorphism, Function Scope, Hoisting and Closures, Functional Programming and Stateless Functions, Immediately Invoked Function Expressions, Interfaces, JavaScript Style Guide, Lambdas, Method Chaining and Fluent APIs, Method Context, Named Parameters, Node Modules, Object Factories, Partial Application and Currying, Plugins, Principles of Modularity, Prototypal Inheritance, Prototype Cloning and the Flyweight Pattern, The Module Pattern, Unit Testing, Coming soon:, Architecting for Scale, Collaboration, Build, Continuous Integration, Deployment, Communicating with Servers and APIs, Designing and Programming RESTful APIs with Node.js, Event-driven, Modular Client Side Application Architecture, Feature Toggles, Internationalization, Logging and Cross Cutting Concerns, Separatian of Concerns (MVC, etc.)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值