• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
龙星之峰
抓住时间,改变现状
博客园    首页    新随笔    联系   管理    订阅  订阅

JavaScript学习与实践(22)

 

 JS Boolean对象,用于转换非布尔型到布尔型,

例子:

<html>
<body>
<script type="text/javascript">
var b1=new Boolean( 0)
var b2=new Boolean(1)
var b3=new Boolean("")
var b4=new Boolean(null)
var b5=new Boolean(NaN)
var b6=new Boolean("false")
document.write("0 is boolean "+ b1 +"<br />")
document.write("1 is boolean "+ b2 +"<br />")
document.write("An empty string is boolean "+ b3 + "<br />")
document.write("null is boolean "+ b4+ "<br />")
document.write("NaN is boolean "+ b5 +"<br />")
document.write("The string 'false' is boolean "+ b6 +"<br />")
</script>
</body>
</html>
大家可以去运行以下
下面是一个比较全面的参考

Boolean Object Methods

FF: Firefox, N: Netscape, IE: Internet Explorer

Method Description FF N IE
toSource() Represents the source code of an object 1 4 -
toString() Converts a Boolean value to a string and returns the result 1 4 4
valueOf() Returns the primitive value of a Boolean object 1 4 4


Boolean Object Properties

Property Description FF N IE 
constructor A reference to the function that created the object 1 2 4
prototype Allows you to add properties and methods to the object 1 2 4

posted @ 2007-01-31 12:15  lxsohu  阅读(472)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3