js二维数组.docx
- 文档编号:8915896
- 上传时间:2023-05-16
- 格式:DOCX
- 页数:25
- 大小:20.96KB
js二维数组.docx
《js二维数组.docx》由会员分享,可在线阅读,更多相关《js二维数组.docx(25页珍藏版)》请在冰点文库上搜索。
js二维数组
创建脚本块
1:
2:
JavaScriptcodegoeshere
3:
2隐藏脚本代码
1:
2:
--
3:
document.write(“Hello”);
4:
//-->
5:
在不支持JavaScript的浏览器中将不执行相关代码
3浏览器不支持的时候显示
1:
2:
Hellotothenon-JavaScriptbrowser.
3:
4链接外部脚本文件
1:
5注释脚本 1: //Thisisacomment 2: document.write(“Hello”);//Thisisacomment 3: /* 4: Allofthis 5: isacomment 6: */ 6输出到浏览器 1: document.write(“Hello”); 7定义变量 1: varmyVariable=“somevalue”; 8字符串相加 1: varmyString=“String1”+“String2”; 9字符串搜索 1: 2: -- 3: varmyVariable=“Hellothere”; 4: vartherePlace=myVariable.search(“there”); 5: document.write(therePlace); 6: //--> 7: 10字符串替换 1: thisVar.replace(“Monday”,”Friday”); 11格式化字串 1: 2: -- 3: varmyVariable=“Hellothere”; 4: document.write(myVariable.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: 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: varfirstString=“MyString”; 19: varfinalString=firstString.bold().toLowerCase().fontcolor(“red”); 20: //--> 21: 12创建数组 1: 2: -- 3: varmyArray=newArray(5); 4: myArray[0]=“FirstEntry”; 5: myArray[1]=“SecondEntry”; 6: myArray[2]=“ThirdEntry”; 7: myArray[3]=“FourthEntry”; 8: myArray[4]=“FifthEntry”; 9: varanotherArray=newArray(“FirstEntry”,”SecondEntry”,”ThirdEntry”,”FourthEntry”,”FifthEntry”); 10: //--> 11: 13数组排序 1: 2: -- 3: varmyArray=newArray(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: 14分割字符串 1: 2: -- 3: varmyVariable=“a,b,c,d”; 4: varstringArray=myVariable.split(“,”); 5: document.write(stringArray[0]); 6: document.write(stringArray[1]); 7: document.write(stringArray[2]); 8: document.write(stringArray[3]); 9: //--> 10: 15弹出警告信息 1: 2: -- 3: window.alert(“Hello”); 4: //--> 5: 16弹出确认框 1: 2: -- 3: varresult=window.confirm(“ClickOKtocontinue”); 4: //--> 5: 17定义函数 1: 2: -- 3: functionmultiple(number1,number2){ 4: varresult=number1*number2; 5: returnresult; 6: } 7: //--> 8: 18调用JS函数 1: 2: functionName"()”>Linktext 19在页面加载完成后执行函数 1: 2: Bodyofthepage 3:
”);
”);
”);
”);
”);
”);
”);
”);
”);
”);
”);
”);
”);