Ajax 板


LINE

嗯 我要说的是sleep (ms) 让执行绪休息并锁定一阵子的code (同步模式) 一般来讲常见都是写while(true)吧 或者是弄成window.setTimeout() while(true)真的是不用考虑了, 稳操爆browser,除非你要停的时间很短。随便跑都占掉80% cpu起跳... 可是 setTimeout() 不是同步的, 所以要用比较复杂的方式达到同步锁定的, 我在这点上脑袋打结了两天,还没有想到一个比较好的方式。:P 刚刚看到一个贱招 , 据说是IE only (我只是看说明这样写, 没用过model对话盒...XD) 不过有效的能有效的同步锁住资料,也是利用setTimeout() 算是蛮有效解决我的问题,post过来分享看看, 并询问一下各位同好有没有更好的作法。:P 原码我看到的地方是 http://www.ozzu.com/ftopic66049.html ──────────────────────────────── /** *@description pause( iMilliseconds ) Cause the single Javascript thread to hald/pause/sleep/wait for a specified period of time, by opening in modalDialog window (IE only) that modally locks the browser until it returns. This modal dialog is not opened to any page, but uses the Javascript: protocol to execute a javascript setTimeout. In this modal context the setTimeout, has the desired affect of preventing any other script execution. The sole purpose of the timeout execution script is to close the modal dialog which will return control/unluck the browser. The intention was to find a way to allow the UI to be updated and rendered in the middle of function/method without the need to split the method up, remove nested calls, or use closures. Used in this fashion to update the UI, a 0 (zero) is usually passed (or optionally omitted altogether) so that the only delay is for the UI to render. *@version Note Please be aware that the user interface WILL update its rendering (if you've made and DOM/CSS/Text changes they will appear) and this may significantly slow down program execution if looping. *@keywords pause sleep wait halt javascript show modal dialog set timeout multi-threaded single thread *@version 1.2 * @param {Object} iMilliseconds [optional] the number of milliseconds the code will pause before returning - If no value is passed the code will returned immediately (as if a 0 were passed) * @return undefined there is no return value from this function */ function pause( iMilliseconds ) { var sDialogScript = 'window.setTimeout( function () { window.close(); }, ' + iMilliseconds + ');'; window.showModalDialog( 'javascript:document.writeln ("<script>' + sDialogScript + '<' + '/script>")'); } --  ▄▅▆▇███▇▆▅▄▃        ╰┼╯─╮ ╮         ◥███████████◣       ╰┼╯=│=│         ◥██████───────    *. ╯  ╯ ╯ の 物 语 .*  ◥███████──────◣ ~ ◢◣             ◢◣  ◥██████───────◤   ◥◤  空白的世界.翼 ◥◤  ◥██▁▂▃▄▅▆▇███▆▅▄▃▂▂telnet://tony1223.no-ip.info --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.232.16.81 ※ 编辑: TonyQ 来自: 125.232.16.81 (09/20 03:37)
1F:→ TonyQ:好吧 , 它并不是那麽的好用 , 当它开启的时候会挡到原本页面 09/20 04:44
2F:→ TonyQ:的事件 , 真是遗憾 orz 09/20 04:45
3F:推 gpmm:能否说一下要做到什麽样的同步锁定?我之前也有简易锁锁锁过 09/20 09:24
4F:推 TonyQ:然後我今天又发现这个东西 需要开启快显示窗 09/20 15:23







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP