JavaScript对象

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 06:19 点击:

 我们要开始学习内建的 JavaScript 对象,以及如何使用它们。从下一节开始,我们将具体地依次讲解的这些内建的 JavaScript 对象。 
1、  字符串对象 
例子1:计算字符串长度 
<html> 
<body> 
 
<script type="text/javascript"> 
 
var txt="Hello World!" 
document.write(txt.length) 
 
</script> 
 
</body> 
</html> 
         
        例子2:为字符串添加样式 
        <html> 
<body> 
 
<script type="text/javascript"> 
 
var txt="Hello World!" 
 
document.write("<p>Big: " + txt.big() + "</p>") 
document.write("<p>Small: " + txt.small() + "</p>") 
 
document.write("<p>Bold: " + txt.bold() + "</p>") 
document.write("<p>Italic: " + txt.italics() + "</p>") 
 
document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>") 
document.write("<p>Fixed: " + txt.fixed() + "</p>") 
document.write("<p>Strike: " + txt.strike() + "</p>") 
 
document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>") 
document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>") 
 
document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>") 
document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>") 
 
document.write("<p>Subscript: " + txt.sub() + "</p>") 
document.write("<p>Superscript: " + txt.sup() + "</p>") 
 
document.write("<p>Link: " + txt.link("http://www.w3school.com.cn") + "</p>") 
</script> 
 
</body> 
</html> 
 
indexOf() 方法 
如何使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置。 
match() 方法 
如何使用 match() 来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。 
<html> 
<body> 
 
<script type="text/javascript"> 
 
var str="Hello world!" 
document.write(str.match("world") + "<br />") 
document.write(str.match("World") + "<br />") 
document.write(str.match("worlld") + "<br />") 
document.write(str.match("world!")) 
 
</script> 
 
</body> 
</html> 
如何替换字符串中的字符 - replace() 
如何使用 replace() 方法在字符串中用某些字符替换另一些字符。 
<html> 
<body> 
 
<script type="text/javascript"> 
 
var str="Visit Microsoft!" 
document.write(str.replace(/Microsoft/,"W3School")) 
 
</script> 
</body> 
</html> 
 
 
 
 
2、JavaScript Date(日期)对象 
定义日期 
Date 对象用于处理日期和时间。 
可以

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Gb2312转utf-8编码的方法(vbs+js)
      • 如何使用Ajax技术开发Web应用程序(1)
      • js跳转路径问题
      • JavaScript模仿桌面窗口
      • 用js检测两个线段是否相交
      • 运用JavaScript构建你的第一个Metro式应用程序(on Windows
      • 我知道的JavaScript -- 设计模式(桥接)应用之 – 验证器
      • 我是如何去了解jquery的(六),案例之幻灯片轮换
      • Jquery封装幻灯片效果
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1