javasript 函数 2(42页).doc
《javasript 函数 2(42页).doc》由会员分享,可在线阅读,更多相关《javasript 函数 2(42页).doc(42页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-javasript 函数 2-第 42 页JavaScript就这么回事1:基础知识 1 创建脚本块 1: 2: JavaScript code goes here 3: 2 隐藏脚本代码 1: 2: 5: 在不支持JavaScript的浏览器中将不执行相关代码 3 浏览器不支持的时候显示 1: 2: Hello to the non-JavaScript browser. 3: 4 链接外部脚本文件 1: 5 注释脚本 1: / This is a comment 2: document.write(“Hello”); / This is a comment 3: /* 4: All of
2、 this 5: is a comment 6: */ 6 输出到浏览器 1: document.write(“Hello”); 7 定义变量 1: var myVariable = “some value”; 8 字符串相加 1: var myString = “String1” + “String2”; 9 字符串搜索 1: 2: 7: 10 字符串替换 1: thisVar.replace(“Monday”,”Friday”); 11 格式化字串 1: 2: ! 3: var myVariable = “Hello there”; 4: document.write(myVariable
3、.big() + “”); 5: document.write(myVariable.blink() + “”); 6: document.write(myVariable.bold() + “”); 7: document.write(myVariable.fixed() + “”); 8: document.write(myVariable.fontcolor(“red”) + “”); 9: document.write(myVariable.fontsize(“18pt”) + “”); 10: document.write(myVariable.italics() + “”); 11
4、: document.write(myVariable.small() + “”); 12: document.write(myVariable.strike() + “”); 13: document.write(myVariable.sub() + “”); 14: document.write(myVariable.sup() + “”); 15: document.write(myVariable.toLowerCase() + “”); 16: document.write(myVariable.toUpperCase() + “”); 17: 18: var firstString
5、 = “My String”; 19: var finalString = firstString.bold().toLowerCase().fontcolor(“red”); 20: / 21: 12 创建数组 1: 2: 11: 13 数组排序 1: 2: 11: 14 分割字符串 1: 2: 10: 15 弹出警告信息 1: 2: 5: 16 弹出确认框 1: 2: 5: 17 定义函数 1: 2: 8: 18 调用JS函数 1: Link text 2: Link text 19 在页面加载完成后执行函数 1: 2: Body of the page 3: 20 条件判断 1: 2:
6、7: 21 指定次数循环 1: 2: ! 3: var myArray = new Array(3); 4: myArray0 = “Item 0”; 5: myArray1 = “Item 1”; 6: myArray2 = “Item 2”; 7: for (i = 0; i myArray.length; i+) 8: document.write(myArrayi + “”); 9: 10: / 11: 22 设定将来执行 1: 2: 8: 23 定时执行函数 1: 2: 9: 24 取消定时执行 1: 2: 9: 25 在页面卸载时候执行函数 1: 2: Body of the pa
7、ge 3: JavaScript就这么回事2:浏览器输出 26 访问document对象 1: 2: var myURL = document.URL; 3: window.alert(myURL); 4: 27 动态输出HTML 1: 2: document.write(“Heres some information about this document:”); 3: document.write(“”); 4: document.write(“Referring Document: “ + document.referrer + “”); 5: document.write(“Domai
8、n: “ + document.domain + “”); 6: document.write(“URL: “ + document.URL + “”); 7: document.write(“”); 8: 28 输出换行 1: document.writeln(“a”); 2: document.writeln(“b”); 29 输出日期 1: 2: var thisDate = new Date(); 3: document.write(thisDate.toString(); 4: 30 指定日期的时区 1: 2: var myOffset = -2; 3: var currentDat
9、e = new Date(); 4: var userOffset = currentDate.getTimezoneOffset()/60; 5: var timeZoneDifference = userOffset - myOffset; 6: currentDate.setHours(currentDate.getHours() + timeZoneDifference); 7: document.write(“The time and date in Central Europe is: “ + currentDate.toLocaleString(); 8: 31 设置日期输出格式
10、 1: 2: var thisDate = new Date(); 3: var thisTimeString = thisDate.getHours() + “:” + thisDate.getMinutes(); 4: var thisDateString = thisDate.getFullYear() + “/” + thisDate.getMonth() + “/” + thisDate.getDate(); 5: document.write(thisTimeString + “ on “ + thisDateString); 6: 32 读取URL参数 1: 2: var url
11、Parts = document.URL.split(“?”); 3: var parameterParts = urlParts1.split(“&”); 4: for (i = 0; i parameterParts.length; i+) 5: var pairParts = parameterPartsi.split(“=”); 6: var pairName = pairParts0; 7: var pairValue = pairParts1; 8: document.write(pairName + “ :“ +pairValue ); 9: 10: 你还以为HTML是无状态的么
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- javasript 函数 242页 42
限制150内