JavaScript基本入门语法集合


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

<script language=”JavaScript”>
<!--
document.write(“Hello”);
// -->
</script>

浏览器不支持的时候显示

<noscript>
Hello to the non-JavaScript browser.
</noscript>

链接外部脚本文件

<script language=”JavaScript” src="/”youname.js"”></script>

注释脚本

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

输出到浏览器

document.write(“<strong>输出内容</strong>”);

定义变量

var myVariable = “some value”;

字符串相加

var myString = “String1” + “String2”;

字符串搜索

<script language=”JavaScript”>
<!--
var myVariable = “Hello there”;
var therePlace = myVariable.search(“there”);
document.write(therePlace);
// -->
</script>

字符串替换

thisVar.replace(“Monday”,”Friday”);

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3