JavaScritp( for 循环语句的理解 )

for 循环的执行过程;

for (var i=0; i<6, i++) {
   console.log(i)
}

第一步:var i= 0;(只执行一次)
第二步:i<8 (判断条件);
第三部: { console.log(i) } 执行语句
第四步: i++ 
第四步执行之后再去执行第二步;以此循环直到满足i<8( 判断条件   )

执行上面的代码输出:
0
1
2
3
4
5


换成这样

for (var i=0; i<6, i++) {
}
console.log(i);

输出6;


这时打印i的值时,循环语句已经执行完;最后的值为6;
过程:

当i = 5;


执行语句:
console.log(5);


语句执行完毕之后执行 i++;此时 i = 5+1 ; i=6;


这时再去执行判断语句;6 == 6;循环结束;

打印结果为6;


javascrtpt 实现窗口拖拽、移动功能、显示坐标代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html <head runat="server"> <title></title> [removed] var mouseX, mouseY; var objX, objY; var isDowm = false; //是否按下鼠标 function mouseDown(obj, e) { obj.style.cursor = "move"; objX = div1.style.left; objY = div1.style.top; mouseX = e.clientX; mouseY = e.clientY; isDowm = true; } function mouseMove(e) { var div = document.getElementById("div1"); var x = e.clientX; var y = e.clientY; if (isDowm) { div.style.left = parseInt(objX) + parseInt(x) - parseInt(mouseX) + "px"; div.style.top = parseInt(objY) + parseInt(y) - parseInt(mouseY) + "px"; document.getElementById("span1")[removed] = "x:" + div.style.top + " " + "y:" + div.style.left; } } function mouseUp(e) { if (isDowm) { var x = e.clientX; var y = e.clientY; var div = document.getElementById("div1"); div.style.left = (parseInt(x) - parseInt(mouseX) + parseInt(objX)) + "px"; div.style.top = (parseInt(y) - parseInt(mouseY) + parseInt(objY)) + "px"; document.getElementById("span2")[removed] = "x:" + div.style.top + " " + "y:" + div.style.left; mouseX = x; rewmouseY = y; div1.style.cursor = "default"; isDowm = false; } } [removed] </head> <body> <span id="span1"></span></br><span id="span2"></span></br> <div id="div1" Green; border: 1px solid red; height: 300px; top: 100px; left: 100px; width: 300px; position: absolute;" </div> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值