⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javascript2.htm

📁 javascript基础教程适合初学javascript的人下载一个很快就能掌握其中的知识.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
a{ text-decoration: none }
p{ line-height:140% }
.text{ font-size: 9pt }
.text{ text-align:justify }
.text11{ font-size: 11pt }
.text11{ text-align:justify }
-->
</style>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>网页教程-JavaScript技术讲座:第二讲 JavaScript基本数据结构 </title>
</head>

<body>

<p align="center">
</p>

<p><span class="text">您现在的位置:<a href="javascript:if(confirm('http://www.4gee.com/Index.htm  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.4gee.com/Index.htm'" tppabs="http://www.4gee.com/Index.htm">主页</a>-<a
href="javascript:if(confirm('http://www.4gee.com/colleges/Index.htm  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.4gee.com/colleges/Index.htm'" tppabs="http://www.4gee.com/colleges/Index.htm">网络教室</a>-<a href="Index.htm" tppabs="http://www.4gee.com/colleges/homepages/Index.htm">主页工厂</a>-JavaScript技术讲座:第二讲 
JavaScript基本数据结构</span></p>

<p align="center"><small><a href="JavaScript1.htm" tppabs="http://www.4gee.com/colleges/homepages/JavaScript1.htm">上一页</a> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="JavaScript3.htm" tppabs="http://www.4gee.com/colleges/homepages/JavaScript3.htm">下一页</a></small></p>

<table border="0" width="100%">
  <tr>
    <td width="100%"><p align="center"><span style="color: rgb(252,177,3)" class="text11">JavaScript技术讲座<br>
    第二讲 JavaScript基本数据结构</span></td>
  </tr>
</table>

<table border="0" width="100%">
  <tr>
    <td width="100%"><span style="color: rgb(125,125,125)" class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    JavaScript提供脚本语言的编程与C++非常相似,它只是去掉了C语言中有关指针等容易产生的错误,并提供了功能强大的类库。对于已经具备C++或C语言的人来说,学习JavaScript脚本语言是一件非常轻松愉快的事。</span><p><span
    style="color: rgb(125,125,125)" class="text"><font color="#009933">一、JavaScript代码的加入</font></span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript的脚本包括在HTML中,它成为HTML文档的一部分。与HTML标识相结合,构成了一个功能强大的Internet网上编程语言。可以直接将JavaScript脚本加入文档:</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;Script Language 
    =&quot;JavaScript&quot;&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript语言代码;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript 语言代码; </span></p>
    <p><span style="color: rgb(125,125,125)" class="text">....</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;/Script&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">说明:</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">  通过标识&lt;Script&gt;...&lt;/Script&gt;指明JavaScript脚本源代码将放入其间。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">  通过属性Language 
    =&quot;JavaScript&quot;说明标识中是使用的何种语言,这里是JavaScript语言, 
    表示在JavaScript中使用的语言。</span></p>
    <p> </p>
    <p><span style="color: rgb(125,125,125)" class="text">下面是将JavaScript脚本加入Web文档中的例子:</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">Test2.html</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;HTML&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;Head&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;Script Language 
    =&quot;JavaScript&quot;&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">document. Write(&quot;这是电脑报网络学校&quot;);</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">document. close();</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;/Script&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;/Head&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">&lt;/HTML&gt;</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">  在浏览器的窗口中调用test2.html,则显示“这是电脑报网络学校”字串。见图2所示。</span></p>
    <p><img src="javascript/002.gif" tppabs="http://www.4gee.com/colleges/homepages/javascript/002.gif" width="212" height="230" alt="002.gif (7229 字节)"></p>
    <p> </p>
    <p><span style="color: rgb(125,125,125)" class="text">图2 </span></p>
    <p><span style="color: rgb(125,125,125)" class="text">说明:</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> Document. write()是文档对象的输出函数,其功能是将括号中的字符或变量值输出到窗口;document. 
    close()是将输出关闭。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 可将&lt;Script&gt;...&lt;/Script&gt;标识放入head&gt;.. 
    &lt;/Head&gt;或&lt;Body&gt; ...&lt;/Body&gt;之间。将JavaScript标识放置&lt;Head&gt;... 
    &lt;/Head&gt;在头部之间,使之在主页和其余部分代码之前装载,从而可使代码的功能更强大;可以将JavaScript标识放置在&lt;Body&gt;... 
    &lt;/Body&gt;主体之间以实现某些部分动态地创建文档。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"><font color="#009933">二、基本数据类型 
    </font></span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript脚本语言同其它语言一样,有它自身的基本数据类型、表达式和算术运算符以及程序的基本框架结构。JavaScript提供了四种基本的数据类型用来处理数字和文字, 
    而变量提供存放信息的地方, 表达式则可以完成较复杂的信息处理。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">1、基本数据类型</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">在JavaScript中四种基本的数据类型:数值(整数和实数)、字符串型(用“”号或‘’括起来的字符或数值)、布尔型(使True或False表示)和空值。在JavaScript的基本类型中的数据可以是常量,也可以变量。由于JavaScript采用弱类型的形式,因而一个数据的变量或常量不必首先作声明,而是在使用或赋值时确定其数据的类型的。当然也可以先声明该数据的类型,它是通过在赋值时自动说明其数据类型的。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">2、常量</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 整型常量</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript的常量通常又称字面常量,它是不能改变的数据。其整型常量可以使用十六进制、八进制和十进制表示其值。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 实型常量</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">实型常量是由整数部分加小数部分表示,如12.32、193.98 
    。可以使用科学或标准方法表示:5E7、4e5等。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 布尔值</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">布尔常量只有两种状态:True或False。 
    它主要用来说明或代表一种状态或标志,以说明操作流程。它与C++是不一样的,C++可以用1或0表示其状态,而JavaScript只能用True或False表示其状态。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 字符型常量</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">使用单引号(‘)或双引号(“)括起来的一个或几个字符。如 
    &quot;This is a book of JavaScript &quot;、&quot;3245&quot;、&quot;ewrt234234&quot; 
    等。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 空值</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript中有一个空值null,表示什么也没有。如试图引用没有定义的变量,则返回一个Null值。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 特殊字符</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">同C语言一样,JavaScript中同样以有些以反斜杠(/)开头的不可显示的特殊字符。通常称为控制字符。</span></p>
    <p> </p>
    <p><span style="color: rgb(125,125,125)" class="text">3、变量</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">变量的主要作用是存取数据、提供存放信息的容器。对于变量必须明确变量的命名、变量的类型、变量的声明及其变量的作用域。</span></p>
    <p><span style="color: rgb(125,125,125)" class="text"> 变量的命名</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">JavaScript中的变量命名同其计算机语言非常相似,这里要注意以下两点:</span></p>
    <p><span style="color: rgb(125,125,125)" class="text">A、必须是一个有效的变量,即变量以字母开头,中间可以出现数字如test1、text2等。除下划线(-)作为连字符外,变量名称不能有空格、(+)、(-)、(,)或其它符号。</span></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -