首页 > 代码库 > JavaScript基础知识

JavaScript基础知识

创建脚本块
<script language=”JavaScript”>
      JavaScript code goes here
</script>

隐藏脚本代码
<script language=”JavaScript”>
<!--
      document.write(“Hello”);
// -->
</script>
在不支持JavaScript的浏览器中将不执行相关代码

浏览器不支持的时候显示
<noscript>
    Hello to the non-JavaScript browser.
</noscript>

链接外部脚本文件
<script language=”JavaScript” src="http://www.mamicode.com/”filename.js"”></script>

注释脚本

// This is a comment
document.write(“Hello”); // This is a comment
/*
      All of this  is a comment
*/

输出到浏览器
document.write(“<strong>Hello</strong>”);

定义变量
1var myVariable = “some value”;

字符串相加
1var myString = “String1” + “String2”;

字符串搜索
<script language=”JavaScript”>
<!--
     var myVariable = “Hello there”;
     var therePlace = myVariable.search(“there”);
    document.write(therePlace);
// -->
7</script> 

JavaScript基础知识