zoukankan      html  css  js  c++  java
  • Javascript强制转换

    Javascript强制转换

      Javascript强制转换强制转换一共有五种转换方式,各有各的用处,希望大家在实际的使用中灵活运用,不要死板。

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title></title>
     6 </head>
     7 <body>
     9     <script>
    10         // 其他类型转化为布尔型
    11         test=Boolean(0);
    12         test=Boolean(-2);
    13         test=Boolean(NaN);
    14         test=Boolean('');
    15         test=Boolean('0.0');
    16         alert(test);
    17         alert(typeof test);
    18     </script>
    19     <script>
    20         //其他类型转化为字符串
    21         test=String(123);
    22         test=String(123.0);
    23         test=String(123.2);
    24         test=String(true);
    25         alert(test);
    26     </script>
    27     <script>
    28         //其他类型转化为数值型
    29         test=Number('12');
    30         test=Number(true);
    31         test=Number(false);
    32         test=Number('false');
    33         test=Number(undefined);
    34         alert(test);
    35     </script>
    36     <script>
    37         //其他类型化为整型
    38         test=parseInt(123.22);
    39         test=parseInt(NaN);
    40         test=parseInt('123ae');
    41         test=parseInt('123e2,10');
    42         alert(test); // string 以 "0x" 开头,parseInt() 会把 string 的其余部分解析为十六进制的整数。
    43     </script>
    44 </body>
    45 </html>
  • 相关阅读:
    十大开源CRM
    编码转换与网址解码
    1、ADO.NET相关对象一句话介绍
    接口与抽象类对比
    C#中的文件下载问题
    在WinForm下获取粘贴板中HTML格式的数据
    Exchange学习
    用Log Explorer恢复数据的基本操作
    iframe的问题
    再发一个C#版的日历
  • 原文地址:https://www.cnblogs.com/CcPz/p/8231110.html
Copyright © 2011-2022 走看看