惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Know Your Adversary
Know Your Adversary
WordPress大学
WordPress大学
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Fortinet All Blogs
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
Vercel News
Vercel News
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
小众软件
小众软件
The GitHub Blog
The GitHub Blog
量子位
V
Visual Studio Blog
博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CERT Recently Published Vulnerability Notes
The Cloudflare Blog
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
U
Unit 42
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Secure Thoughts
The Hacker News
The Hacker News
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
Help Net Security
Help Net Security
G
GRAHAM CLULEY
Jina AI
Jina AI

博客园 - 猎风

Visio Viewer 2003 & 2007打不开vsd的解决办法,测试有效 项目所需的应用程序未安装,确保已安装项目类型(.csproj)的应用程序的解决办法 - 猎风 - 博客园 一个form两个提交按钮,分别提交到两页面 utf-8页面调用gb2312页面的js显示乱码的解决方法 Access乱码解决方案 - 猎风 - 博客园 Google小组研发模式分析 如何写系统分析书 十年互联网,十个风云人物——历史会记住他们! SQL Server安装时候提示程序挂起 【Mark】convert函数(SQL) 吊西楚霸王 献给蓝 实用文章:常用开源协议详细解析 毕竟充实 FCKeditor 2.0 的设置.修改.使用 关于asp里面的(do while loop )(while wend )(for next)运行的时间 - 猎风 一份ASP代码编写标准 影响中国软件开发的20人 寂寞沙洲冷 关于ASP中堆栈溢出错误的解决 - 猎风 - 博客园 福布斯评最佳与最差老板 TCL上黑榜 瑞星:关于卡巴斯基起诉瑞星的声明 浏览网页乱码怎么办? 下辈子如果我还记得你 致红叶 互联网名人语录小柳点评版 醉酒诗书喜欲狂 报告:中国消费者买得起打印机用不起墨水 alt属性和title属性 instr WINDOWS所有系统文件的用途 2006 企业级PHP应用软件精彩叠现 js常用页面跳转 - 猎风 - 博客园 终于下定决心了 成功的人永不放弃,放弃的人永不成功! js操作数据库 - 猎风 - 博客园 Web 2.0 编程思想 网站 LOGO 设计简论 按比例缩放图片 - 猎风 - 博客园
JavaScript基础知识
猎风 · 2009-07-11 · via 博客园 - 猎风

1 创建脚本块
<script language=”JavaScript”>
      JavaScript code goes here
</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>
注释脚本

// This is a comment
document.write(“Hello”); // This is a comment
/**//*
       All of this   is a comment
*/

6 输出到浏览器
document.write(“<strong>Hello</strong>”);

7 定义变量
1var myVariable = “some value”;

8 字符串相加
1var myString = “String1” + “String2”;

9 字符串搜索
1<script language=”JavaScript”>
2<!--
3      var myVariable = “Hello there”;
4      var therePlace = myVariable.search(“there”);
5     document.write(therePlace);
6// -->
7</script>

10 字符串替换   thisVar.replace(“Monday”,”Friday”);

11 格式化字串
1 <script language=”JavaScript”>
2 <!--
3 var myVariable = “Hello there”;
4 document.write(myVariable.big() + “<br>”);
5 document.write(myVariable.blink() + “<br>”);
6 document.write(myVariable.bold() + “<br>”);
7 document.write(myVariable.fixed() + “<br>”);
8 document.write(myVariable.fontcolor(“red”) + “<br>”);
9 document.write(myVariable.fontsize(“18pt”) + “<br>”);
10 document.write(myVariable.italics() + “<br>”);
11 document.write(myVariable.small() + “<br>”);
12 document.write(myVariable.strike() + “<br>”);
13 document.write(myVariable.sub() + “<br>”);
14 document.write(myVariable.sup() + “<br>”);
15 document.write(myVariable.toLowerCase() + “<br>”);
16 document.write(myVariable.toUpperCase() + “<br>”);
17
18 var firstString = “My String”;
19 var finalString = firstString.bold().toLowerCase().fontcolor(“red”);
20 // -->
21 </script>

12 创建数组
1<script language=”JavaScript”>
2<!--
3 var myArray = new Array(5);
4myArray[0] = “First Entry”;
5 myArray[1] = “Second Entry”;
6 myArray[2] = “Third Entry”;
7 myArray[3] = “Fourth Entry”;
8 myArray[4] = “Fifth Entry”;
9 var anotherArray = new Array(“First Entry”,”Second Entry”,”Third Entry”,”Fourth Entry”,”Fifth Entry”);
10// -->
11</script>

13 数组排序
1<script language=”JavaScript”>
2<!--
3 var myArray = new Array(5);
4 myArray[0] = “z”;
5 myArray[1] = “c”;
6 myArray[2] = “d”;
7 myArray[3] = “a”;
8 myArray[4] = “q”;
9 document.write(myArray.sort());
10// -->
11</script>

14 分割字符串
1<script language=”JavaScript”>
2<!--
3 var myVariable = “a,b,c,d”;
4 var stringArray = myVariable.split(“,”);
5 document.write(stringArray[0]);
6 document.write(stringArray[1]);
7 document.write(stringArray[2]);
8 document.write(stringArray[3]);
9// -->
10</script>

15 弹出警告信息
1<script language=”JavaScript”>
2<!--
3      window.alert(“Hello”);
4// -->
5</script>

16 弹出确认框
1<script language=”JavaScript”>
2<!--
3 var result = window.confirm(“Click OK to continue”);
4// -->
5</script>

17 定义函数
1<script language=”JavaScript”>
2 <!--
3 function multiple(number1,number2) {
4 var result = number1 * number2;
5 return result;
6 }
7// -->
8</script>

18 调用JS函数
1<a href=”#” onClick=”functionName()”>Link text</a>
2<a href="/”javascript:functionName"()”>Link text</a>

19 在页面加载完成后执行函数
1<body onLoad=”functionName();”>
2       Body of the page
3</body>

20 条件判断
1<script>
2<!--
3 var userChoice = window.confirm(“Choose OK or Cancel”);
4 var result = (userChoice == true) ? “OK” : “Cancel”;
5 document.write(result);
6// -->
7</script>

21 指定次数循环
1<script>
2<!--
3 var myArray = new Array(3);
4 myArray[0] = “Item 0”;
5 myArray[1] = “Item 1”;
6 myArray[2] = “Item 2”;
7 for (i = 0; i < myArray.length; i++) {
8 document.write(myArray[i] + “<br>”);
9 }
10// -->
11</script>
12

22 设定将来执行
1<script>
2<!--
3 function hello() {
4 window.alert(“Hello”);
5 }
6 window.setTimeout(“hello()”,5000);
7// -->
8</script>
9

23 定时执行函数
1<script>
2<!--
3 function hello() {
4        window.alert(“Hello”);
5         window.setTimeout(“hello()”,5000);
6 }
7 window.setTimeout(“hello()”,5000);
8// -->
9</script>

24 取消定时执行
1<script>
2<!--
3 function hello() {
4           window.alert(“Hello”);
5 }
6 var myTimeout = window.setTimeout(“hello()”,5000);
7 window.clearTimeout(myTimeout);
8// -->
9</script>

25 在页面卸载时候执行函数
1<body onUnload=”functionName();”>
2      Body of the page
3</body>