JavaScript就这么回事 (JS基础知识整理)
1 创建脚本块
引用内容程序代码
<script language=”JavaScript”>
JavaScript 代码写在这里面
</script>
2 隐藏脚本代码
引用内容程序代码
<script language=”JavaScript”>
<!--
document.write(“Hello”);
// -->
</script>
在不支持JavaScript的浏览器中将不执行相关代码
3 浏览器不支持的时候显示
引用内容程序代码
<noscript>
Hello to the non-JavaScript browser.
</noscript>
4 链接外部脚本文件
引用内容程序代码
<script language=”JavaScript” src="/”filename.js"”></script>
5 注释脚本
引用内容程序代码
// This is a comment
document.write(“Hello”); // This is a comment
/*
All of this
is a comment
*/
6 输出到浏览器
引用内容程序代码
document.write(“<strong>Hello</strong>”);
7 定义变量
引用内容程序代码
var myVariable = “some value”;
8 字符串相加
引用内容程序代码
var myString = “String1” + “String2”;
9 字符串搜索
引用内容程序代码
<script language=”JavaScript”>
<!--
var myVariable = “Hello there”;
var therePlace = myVariable.search(“there”);
document.write(therePlace);
// -->
</script>
10 字符串替换
引用内容程序代码
thisVar.replace(“Monday”,”Friday”);
11 格式化字串
引用内容程序代码
<script language=”JavaScript”>
<!--
var myVariable = “Hello there”;
document.write(myVariable.big() + “<br>”);
document.write(myVariable.blink() + “<br>”);
document.write(myVariable.bold() + “<br>”);
document.write(myVariable.fixed() + “<br>”);
document.write(myVariable.fontcolor(“red”) + “<br>”);
document.write(myVariable.fontsize(“18pt”) + “<br>”);
document.write(myVariable.
相关文档:
var Stack=function(limt_length){
this.stack=new Array();
this.limt=(limt_length)?limt_length:8;
}
Stack.prototype.push=function(o){
if(this.exist(o)){
this.remove(o);
this.stack.unshift(o);
}else{
this.stack.unshift(o);
}
while(t ......
<a href='javascript:add();'>添加</a>
<a href='javascript:del();'>删除</a>
<table width=300 id=tbl>
<tr style='display:none;'><td>11111111111111</td></tr>
<tr style='display:none;'><td>22222222222222</td></tr>
<tr s ......
  ......
变量
1. 如果没有用var语句给一个变量定初始值,它的初始值就是undefined.
2. 尝试给未用var声明的变量赋值,JavaScript会隐式声明该变量。但是,隐式声明的变量总是被创建为全局变量,即使该变量只在一个函数体内使用。
3. ......
ECMA 本周推出了 JavaScript 5(PDF),除了增强基础函数库之外,还引入了严格运行时模式(Strict Runtime Modes)以避免代码中的常见错误。ECMA ECMAScript 4 的努力曾以失败告终,ECMA 甚至没有发布 ECMAScript 4 细则。
过去几年,诸如 Nitro,TraceMonkey 一类的 JavaScript 引擎发展迅猛,JavaScript 成了 Google Wa ......