JavaScript基础语法总结

林继 VPS 知识 11,574 共写了951个字 (2007-03-03 15:44:13) 没有评论 打印 扫描二维码 百度已收录

From:http://www.im286.com/viewthread.php?tid=1859832

创建脚本块

  1. <script language="JavaScript"><br/>JavaScript code goes here<br/></script>

隐藏脚本代码

  1. <script language="JavaScript"><br/><!--<br/>document.write("Hello");<br/>// --><br/></script>


浏览器不支持的时候显示

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

链接外部脚本文件

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

注释脚本

  1. // This is a comment<br/>document.write("Hello"); // This is a comment<br/>/*<br/>All of this<br/>is a comment<br/>*/ &nbsp;

输出到浏览器

  1. document.write("<strong>输出内容</strong>");

定义变量

  1. var myVariable = "some value";

字符串相加

  1. var myString = "String1" + "String2";

字符串搜索

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

字符串替换

  1. thisVar.replace("Monday","Friday");

格式化字串

  1. <script language="JavaScript"><br/><!--<br/>var myVariable = "Hello there";<br/>document.write(myVariable.big() + "<br>");<br/>document.write(myVariable.blink() + "<br>");<br/>document.write(myVariable.bold() + "<br>");<br/>document.write(myVariable.fixed() + "<br>");<br/>document.write(myVariable.fontcolor("red") + "<br>");<br/>document.write(myVariable.fontsize("18pt") + "<br>");<br/>document.write(myVariable.italics() + "<br>");<br/>document.write(myVariable.small() + "<br>");<br/>document.write(myVariable.strike() + "<br>");<br/>document.write(myVariable.sub() + "<br>");<br/>document.write(myVariable.sup() + "<br>");<br/>document.write(myVariable.toLowerCase() + "<br>");<br/>document.write(myVariable.toUpperCase() + "<br>");<br/>var firstString = "My String";<br/>var finalString = firstString.bold().toLowerCase().fontcolor("red");<br/>// --><br/></script>

创建数组

  1. <script language="JavaScript"><br/><!--<br/>var myArray = new Array(5);<br/>myArray[0] = "First Entry";<br/>myArray[1] = "Second Entry";<br/>myArray[2] = "Third Entry";<br/>myArray[3] = "Fourth Entry";<br/>myArray[4] = "Fifth Entry";<br/>var anotherArray = new Array("First Entry","Second Entry","Third Entry","Fourth Entry","Fifth Entry");<br/>// --><br/></script>

历史上的今天

3月
3
分页阅读: 1 2 下一页

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

< >