本文和大家重点讨论一下常用JavaScript方法和技巧,主要包括创建脚本块,隐藏脚本代码,链接外部脚本文件等技巧,希望通过本文的学习你对JavaScript方法和技巧有一定的认识。
常用JavaScript方法和技巧
创建脚本块
- 1
- 2JavaScriptcodegoeshere
- 3
隐藏脚本代码
- 1
- 2
- 5
浏览器不支持的时候显示
- 1
- 2Hellotothenon-JavaScriptbrowser.
- 3
链接外部脚本文件
- 1
JavaScript方法之注释脚本
- 1//Thisisacomment
- 2document.write(“Hello”);//Thisisacomment
- 3/*
- 4Allofthis
- 5isacomment
- 6*/
输出到浏览器
- 1document.write(“Hello”);
定义变量
- 1varmyVariable=“somevalue”;
字符串相加
- 1varmyString=“String1”+“String2”;
JavaScript方法之字符串搜索
- 1
- 2varmyVariable=“Hellothere”;
- 3vartherePlace=myVariable.search(“there”);
- 4document.write(therePlace);
- 5
字符串替换
- 1
- 2thisVar.replace(“Monday”,”Friday”);
- 3
【编辑推荐】
上一篇:Android数据库事务浅析
下一篇:改进服务器虚拟化 可有效节约空间