发布于 2016-12-25 03:06:57 | 137 次阅读 | 评论: 0 | 来源: 网友投递
这里有新鲜出炉的Javascript教程,程序狗速度看过来!
JavaScript客户端脚本语言
Javascript 是一种由Netscape的LiveScript发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
format: function(s, arg0) {
var args = arguments;
return s.replace(/\{(\d+)\}/ig, function(a, b) {
return args[(b | 0) + 1] || '';
});
}
function ReplaceDemo(){
var r, re; // 声明变量。
var ss = "The man hit the ball with the bat.\n";
ss += "while the fielder caught the ball with the glove.";
re = /The/g; // 创建正则表达式模式。
r = ss.replace(re, "A"); // 用 "A" 替换 "The"。
return(r); // 返回替换后的字符串。
}
ReplaceDemo(); //A man hit the ball with the bat. while the fielder caught the ball with the glove.
function ReplaceDemo(){
var r, re; // 声明变量。
var ss = "The rain in Spain falls mainly in the plain.";
re = /(\S+)(\s+)(\S+)/g; // 创建正则表达式模式。
r = ss.replace(re, "$3$2$1"); // 交换每一对单词。
return(r); // 返回结果字符串。
}
document.write(ReplaceDemo()); //rain The Spain in mainly falls the in plain.
function f2c(s){
var test = /(\d+(\.\d*)?)F\b/g; // 初始化模式。
return(s.replace(test,function($0,$1,$2){return((($1-32)) + "C");}));
}
f2c("Water boils at 212F 3F .2F 2.2F .2");//Water boils at 180C -29C .-30C -29.8C .2