当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JScript的条件编译

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JScript的条件编译


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 41 ::
收藏到网摘: n/a

微软对条件编译的解释是:
条件编译的某些典型用途包括使用 Jscript 中的新特性、在脚本中嵌入调试支持以及跟踪代码的运行。
先看一段代码简单的了解下:

var s=0//@cc_on+1
alert(s)

如果你使用的是IE可以看到,浏览器弹出的提示s的值是"1";
var s=0//@cc_on+1
在IE中等同于:
var s=0+1
条件编译为在注释中运行代码提供了途径。
一般我们在编写JavaScript代码时很少用到条件编译。不过条件编译由于其本身的特性,对我们检测系统,自动识别浏览器编程却提供了方便。
有一段很经典的代码:
var isMSIE = /*@cc_on!@*/false;
也可以这样:
var IE=0//@cc_on+1
更复杂点的:
var IEVersion=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; }}()||@*/0;