运算符

Web-JavaScript-JavaScript 运算符

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>javascript 运算符</title>
</head>

<body>
    <!--javascriptyu运算符-->
    <p>惦记按钮计算</p>
    <button οnclick="myFunction0()">点击这里</button>
    <p id="demo0"></p>
    <script>
    function myFunction0() {
        y = 5;
        z = 2;
        x = y + z;
        document.getElementById("demo0").innerHTML = x;
    }
    </script>
    <!--用于字符串的+运算符-->
    <p>点击按钮创建及增加字符串变量</p>
    <button οnclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    <script>
    function myFunction() {
        txt1 = "What a very";
        txt2 = "nice day";
        txt3 = txt1 + txt2;
        document.getElementById("demo").innerHTML = txt3;
    }
    </script>
    <!--在字符串中增加空格-->
    <p>点击按钮创建及增加字符串变量。</p>
    <button οnclick="myFunction1()">点击这里</button>
    <p id="demo1"></p>
    <script>
    function myFunction1() {
        txt1 = "What a very ";
        txt2 = "nice day";
        txt3 = txt1 + txt2;
        document.getElementById("demo1").innerHTML = txt3;
    }
    </script>
    <p>点击按钮创建及增加字符串变量</p>
    <button οnclick="myFunction2()">点击这里</button>
    <p id="demo2"></p>
    <script>
    function myFunction2() {
        txt1 = "what a very";
        txt2 = "nice day";
        txt3 = txt1 + " " + txt2;
        document.getElementById("demo2").innerHTML = txt3;
    }
    </script>
    <!--对字符串和数字进行加法运算-->
    <P>点击按钮创建及增加字符串变量</p>
    <button οnclick="myFunction()">点击这里</button>
    <p id="demo3"></p>
    <script>
    function myFunction() {
        var x = 5 + 5;
        var y = "5" + 5;
        var z = "hello" + 5;


        var demoP = document.getElementById("demo");
        demoP.innerHTML = x + "<br>" + y + "<br>" + z;
    }
    </script>
</body>

</html>

————————————————

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值