首页 » 建站技术 » 浏览内容

JavaScript基础语法总结


2007-03-03 15:44:13 11,549 0 发表评论 字体: 作者:C.K.
标签: javascript

体验版 88 元,个人版 128 元,多用户版 288元个人版160元升级到多用户版。

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

创建脚本块

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

隐藏脚本代码

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


浏览器不支持的时候显示

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

链接外部脚本文件

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

注释脚本

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

输出到浏览器

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

定义变量

var myVariable = "some value";

字符串相加

var myString = "String1" + "String2";

字符串搜索

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

字符串替换

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

格式化字串

<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>

创建数组

<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>

1 2

网站统计 Statistics

  • 创建时间: 2005年1月3日 距今5064 天
  • 日志总数: 2461
  • 评论总数: 630
  • 标签总数: 654
  • 链接总数: 273
  • 最后更新: 2018-8-31 17:57:04
  • 您是本站第 14158492 位访客

广告区 Guǎng Gào