ECMAScrip对象-Global对象

5.6Global对象
全局对象是预定义的对象,作为 JavaScript 的全局函数和全局属性的占位符。通过使用全局对象,可以访问所有其他所有预定义的对象、函数和属性。全局对象不是任何对象的属性,所以它没有名称。

Gloab.png

<pre>

<!DOCTYPE html>
<html>
  <head>
    <title>Global对象.html</title>
    
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="content-type" content='text/html;charset=utf-8'>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    <script type="text/javascript">
        //这个对象类似于java中的工具类它的所有方法都是静态的
        //http协议不支持中文码表
        //encodeURI/decodeURI 可以将中文进行url编码 例如%E5%80%AA%E7%91%9E%E6%98%8E
        //encodeURIComponent/decodeURIComponent//这个转义的范围更大包括符号
        //username=%E5%80%AA%E7%91%9E%E6%98%8E
        //提交表单的时候如果有中文,本质上是提交0101,那么它按拉丁码表进行转化
        //只支持拉丁码表
        //中为->utf-8->0101010->拉丁码表->%E6%98%8E
        var str="http://www.baidu.com?wd=&汤?姆";
        var encodeStr = encodeURI(str);
        alert(encodeStr);
    </script>
  </head>
  
  <body>
    This is my HTML page. <br>
    <a href="encodeStr">点我</a>
  </body>
</html>

</pre>
<pre>

<!DOCTYPE html>
<html>
  <head>
    <title>Global对象.html</title>
    
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="content-type" content='text/html;charset=utf-8'>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    <script type="text/javascript">
        //parseInt  转换成整数的方法 从左到右依次转换转换转换到不能转换的字符
        //parseFloat 转化成浮点数的方法
        var str ='123';
        var num = parseInt(str);
        var num2 = +str;
        var num3 = new Number(str);
        //三种将字符串转化为数字的方法
    //  alert(typeof num);
        var str2 ='123a';
        alert(+str2);//nan
        alert(parseInt(str2))
        
        var str3 ='a123';
        alert(parseInt(str3));
        //转换结果nan
        var str4='3.14.12'
        alert(parseFloat(str4))//3.14
    </script>
  </head>
  
  <body>
    This is my HTML page. <br>
    <a href="http://www.baidu.com">点我</a>
  </body>
</html>

</pre>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>Global对象.html</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content='text/html;charset=utf-8'>
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
//isNaN 判断一个值是否是nan的
    var num = +"123";
    
    if(isNaN(num)){
        alert("是nan");
    }else{
        alert("不是nan");
    }
    //eval()解析运行方法
    
    alert(eval("1+1"));//2
    alert(eval("new String('abc')"));
</script>

</head>

<body>
This is my HTML page.

</body>
</html>
<>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容