原文地址:http://blog.csdn.net/web_hwg/article/details/75045689
方法一
最简单的方法是用一个临时变量
var a = 10, b = 20; var temp = a; a = b; b = temp;
方法二
让其中一个变量变成一个与a和b都有关系的值
a = a + b; b = a - b; a = a - b;
或者
a = a - b; b = a + b; a = b - a;
原文地址:http://blog.csdn.net/web_hwg/article/details/75045689
最简单的方法是用一个临时变量
var a = 10, b = 20; var temp = a; a = b; b = temp;
让其中一个变量变成一个与a和b都有关系的值
a = a + b; b = a - b; a = a - b;
或者
a = a - b; b = a + b; a = b - a;
转载于:https://www.cnblogs.com/lianglanlan/p/8076266.html