JavaScript 零散笔记
JavaScript 零散笔记
1 创建脚本块
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 隐藏脚本代码
1: <script language=”JavaScript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </script>
在不支持JavaScript的浏览器中将不执行相关代码
3 浏览器不支持的时候显示
1: <noscript>
2: Hello to the non-JavaScript browser.
3: </noscript>
4 链接外部脚本文件
1: <script language=”JavaScript” src=../../”filename.js”></script>
5 注释脚本
1: // This is a comment
2: document.write(“Hello”); // This is a comment
3: /*
4: All of this
5: is a comment
6: */
6 输出到浏览器
1: document.write(“<strong>Hello</strong>”);
7 定义变量
1: var myVariable = “some value”;
8 字符串相加
1: var 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 字符串替换
1: 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.w
相关文档:
JavaScript 是 Web 开发与设计中不可或缺的东西,不管是一个简单的网页还是一个专业的站点,也不管你是高手还是菜鸟,如今
JavaScript 库越来越强大,可以胜任许多复杂的工作,然而同时,人们在众多 JavaScript 库面前又觉得无所适从,本文,我们将使用
Google 搜索出排名前 10 位的 JavaScript 库,并对它们逐一进行介绍 ......
网上很多文章都转载了一段话:对于函数来说,caller 属性只有在函数执行时才有定义。
到底是不是呢?可以用下面这段代码测试一下(这段例子也是转载文章中使用的):
function callerDemo() {
if (callerDemo.caller) {
var a= callerDemo.caller.toString();
alert(a);
} else {
......
m=a.getMonth(); //获取月份值
d=a.getDate(); //获取日期值
d1=a.getDay(); //获取当前星期值
h=a.getHours(); //获取当前小时数
m1=a.getMinutes(); //获取当前分钟数
s=a.getSeconds(); //获取当前秒钟数
对象.style.fontSize="文字大小";
单位:mm/cm/in英寸/pc帕/pt点/px象素/em文字高
1in=1.25cm
1pc=12pt
......
注:在项目中遇到类似的问题,通过网络解决问题。
parseInt("07") 返回多少 ?
parseInt("08") 又返回多少 ?
正确答案:
parseInt("07") 返回8
parseInt("08") 返回0
用javascript的parseInt函数时,parseInt("08")或者parseInt("09")返回的居然是0,而parseInt("01")...parseInt("07")都是正确的。
为什么这样呢?
......
使用JavaScript可以将用户导向一个特定的地址,并且不同的方法会对浏览器的历史记录有不同的影响。
实例JavaScript代码
本例定义了两个JavaScript函数,功能都是重定向到首页,但是第一个函数采用的是直接给href赋值的方式,第二个使用的是replace方法。具体请看下面的代码:
<script type="text/javascript"> fun ......