zoukankan      html  css  js  c++  java
  • js中加号(+)的两个作用和基本数据类型转换

    加号(+)的两个作用:

    1、当加号两侧为数值是,则进行相加运算

    2、当加号一侧有字符串是,则进行拼接

    基本数据类型转换:

    1、将数值转换成字符串toString()

        格式:数值变量名.toString()

    2、将字符串转换成整型parseInt()

        注意点:字符串第一个字符只能为数字  如果不是数字 会报NaN  (Not a Number);

        格式:parseInt(字符串变量名)

    3、将字符串转换成浮点型 pareFloat()

        格式:parseFloat(数值变量名)

    如果把数字与字符串相加,结果将成为字符串

    代码演示:

     1 <!DOCTYPE html>
     2 <html>
     3 <head> 
     4 <meta charset="utf-8"> 
     5 <title>菜鸟教程(runoob.com)</title> 
     6 </head>
     7 <body>
     8 
     9 <p>点击按钮创建及增加字符串变量。</p>
    10 <button onclick="myFunction()">点击这里</button>
    11 <p id="demo"></p>
    12 </body>
    13 </html>
    14 <script>
    15 function myFunction()
    16 {
    17     var x=5+5;
    18     var y="5"+5;
    19     var z="Hello"+5;
    20     var demoP=document.getElementById("demo");
    21     demoP.innerHTML=x + "<br>" + y + "<br>" + z;
    22 }
    23 </script>
    View Code

    页面展示

  • 相关阅读:
    H5实现魔方游戏
    T-SQL:CTE用法(十)
    c# API接收Base64转图片
    T-SQL :联接查询练习 (杂)
    T-SQL:基础练习(杂)
    UI5-文档-导航栏
    UI5-文档-4.10-Descriptor for Applications
    UI5-文档-4.9-Component Configuration
    UI5-文档-4.8-Translatable Texts
    UI5-文档-4.7-JSON Model
  • 原文地址:https://www.cnblogs.com/z617182272/p/11375373.html
Copyright © 2011-2022 走看看