【代码笔记】Web-JavaScript-JavaScript 运算符
程序员文章站
2024-01-17 10:58:04
一,效果图。 二,代码。 javascript 运算符
惦记按钮计算
一,效果图。
二,代码。
<!doctype html> <html> <head> <meta charset="utf-8"> <title>javascript 运算符</title> </head> <body> <!--javascriptyu运算符--> <p>惦记按钮计算</p> <button onclick="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 onclick="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 onclick="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 onclick="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 onclick="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>
参考资料:《菜鸟教程》