易截截图软件、单文件、免安装、纯绿色、仅160KB

[翻译]High Performance JavaScript(013)

Conditionals  条件表达式
    Similar in nature to loops, conditionals determine how execution flows through JavaScript. The traditional argument of whether to use if-else statements or a switch statement applies to JavaScript just as it does to other languages. Since different browsers have implemented different flow control optimizations, it is not always clear which technique to use.
    与循环相似,条件表达式决定JavaScript运行流的走向。其他语言使用if-else或者switch表达式的传统观点也适用于JavaScript。由于不同的浏览器针对流程控制进行了不同的优化,使用哪种技术并不总是很清楚。
if-else Versus switch  if-else与switch比较
    The prevailing theory on using if-else versus switch is based on the number of conditions being tested: the larger the number of conditions, the more inclined you are to use a switch instead of if-else. This typically comes down to which code is easier to read. The argument is that if-else is easier to read when there are fewer conditions and switch is easier to read when the number of conditions is large. Consider the following:
    使用if-else或者switch的流行理论是基于测试条件的数量:条件数量较大,倾向于使用switch而不是if-else。这通常归结到代码的易读性。这种观点认为,如果条件较少时,if-else容易阅读,而条件较多时switch更容易阅读。考虑下面几点:
if (found){
  //do something
} else {
  //do something else
}
switch(found){
  case true:
    //do something
    break;
  default:
    //do something else
}
    Though both pieces of code perform the same task, many would argue that the if-else statement is much easier to read than the switch. Increasing the number of conditions, however, usually reverses that opinion:
    虽然两个代码块实现同样任务,很多人会认为if-else表达式比witch表达式更容易阅读。如果增加条件体的数量,通常会扭转这种观点:
if (color == "red"){
  //do


相关文档:

[翻译]High Performance JavaScript(010)

Cloning Nodes  节点克隆
    Another way of updating page contents using DOM methods is to clone existing DOM elements instead of creating new ones—in other words, using element.cloneNode() (where element is an existing node) instead of document.createElement().
 &nbs ......

使用JavaScript连接SqlServer数据库。执行CRUD操作。

function db()
{
//活动编号
var activeid = Request.Form("activeid");
//用户名
var username = Request.Form("username");
//手机号码
var mobile = Request.Form("mobile");
var conn= Server.CreateObject("ADODB.connection");
var rs= Serve ......

javascript跨浏览器创建XML对象


var
 
xmlDoc
 
=
 
null
;
function
 
parseXML
(
xmlUrl
)
{
  try
 
{
    //IE
    xmlDoc
 
=
 
new
 
ActiveXObject
(
"Microsoft.XMLDOM"
);
    xmlDoc
.
async
 
=
 
false
;
    xmlDoc ......

javascript动态装入XML数据


使用javascript创建Microsoft XML DOM,就可以完成这一工作.
// 装入数据.
var source = new ActiveXObject("Microsoft.XMLDOM");
source.async = false
source.load("history.xml");
// 装入样式表.
var stylesheet = new ActiveXObject("Microsoft.XMLDOM");
stylesheet.async = false
stylesheet.load( ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号