Js基础学习资料 |
本文标签:基础学习 1、防止不支持js的浏览器出问题可以这样处理JS代码 <script type="text/javascript"> <!-- document.write("Hello World!"); //--> </script> 2、JS放置位置: header:确保脚本被调用时已经加载 body:页面载入时就调用 外部js文件:不包含<script>标签 用法:<script src = "xxx.js">.....</sceipt> 3、注释 单行:// 多行:/*.....*/ 4、=== 全等符号 表示类型和值都相等 5、三种提示框 警告:alert("alert"); 确认:confirm("confirm"); 提示:prompt("prompt","默认值"); 6、for in 声明 for (变量 in 对象) { 在此执行代码 } 7、正则表达式 test()方法:检索字符串中的指定值,如果有返回True,否则False var patt1=new RegExp("e"); document.write(patt1.test("The best things in life are free")); exec()方法:检索字符中中的指定值,如果有返回找到的值,否则返回null var patt1=new RegExp("e"); document.write(patt1.exec("The best things in life are free")); compile()方法:用于改变检索模式和添加删除第二个参数 |