JavaScript两个变量交换值:
1 <script type="text/javascript"> 2 //交换两个变量的值 3 var number1 = 100; 4 var number2 = 200; 5 6 //方法一:定义第三个变量 7 var number3 = number1; 8 //再进行变量值的交换 9 number1 = number2; 10 number2 = number3; 11 12 //方法二:运算 13 number1 = number1 + number2; 14 number2 = number1 - number2; 15 number1 = number1 - number2; 16 17 </script>