标签:取反 赋值运算符 var 比较运算符 UNC enc element 数据类型 elf
1 <button id="btn" onclick="suanShu()">运算</button> 2 <script> 3 // + - * / % ++ -- 4 var i = 521,j = 1314; 5 var sum = i + j; 6 var difference = j - i; 7 var product = i * j; 8 var quotient = j / i; 9 var congruent = j % i; //j除以i后的余数 10 var addSelf = i++; // ++在前,先+后运算,++在后,先运算后加 此时i= 522 11 var selfCut = --j; // --在前,先+后运算,--在后,先运算后加 此时j=1313 12 function suanShu() { 13 document.getElementById("sumId").innerHTML = "两数相加结果:" + sum; 14 document.getElementById("differenceId").innerHTML = "两数相减结果:" + difference; 15 document.getElementById("productId").innerHTML = "两数相乘结果:" + product; 16 document.getElementById("quotientId").innerHTML = "两数相除结果:" + quotient; 17 document.getElementById("congruentId").innerHTML = "两数取余结果:" + congruent; 18 document.getElementById("addSelfId").innerHTML = "i自加结果:" + addSelf; 19 document.getElementById("selfCutId").innerHTML = "j自减结果:" + selfCut; 20 } 21 </script> 22 <p id="sumId"></p> 23 <p id="differenceId"></p> 24 <p id="productId"></p> 25 <p id="quotientId"></p> 26 <p id="congruentId"></p> 27 <p id="addSelfId"></p> 28 <p id="selfCutId"></p>
1 // = += -+ *= /= %= 2 var x = i+=j; //i = i+j 3 var y = i -=j; //i = i-j 4 var m = i *= j; //i = i*j 5 var n = i /= j; //i = i/j
3)字符串操作
字符串拼接:var i= 5+"5",结果为55.任何数据类型与字符串数据类型相加,都会转换为 字符串类型做处理
4)比较运算符 (== 、=== 、 != 、!==、>、<、>=、<= )
1 <script> 2 var m = 12,n = "12"; 3 var x = 23,y = "23"; 4 document.write(m==n); //true 5 document.write(m===n); //false 6 document.write(m!=x); //true 7 document.write(m!==n); //true 8 document.write(m>y); //false 9 document.write(x<=n) //false 10 </script>
5)逻辑运算符(&&、||、!)
1 <script> 2 var i = 100,j = 200; 3 document.write(i>100 && j<=200); //与,两者都需满足 4 document.write(i>100 || j<=200); //或,两者满足其一 5 document.write(!(i==j)); // 取反 6 </script>
6)条件运算符
<script> var i = 11; document.write(i>10 ? "i大于10":"i小于10"); //条件为真执行前,为假执行后 </script>
标签:取反 赋值运算符 var 比较运算符 UNC enc element 数据类型 elf
原文地址:https://www.cnblogs.com/mxyweb/p/9299472.html