扫码关注官方订阅号
async.queue 点击事件,kill()执行后,执行async,queue,点击第二次,kill()不执行,也不执行async.queue,怎么回事就是这个库
欢迎选择我的课程,让我们一起见证您的进步~~
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>爬虫小测试</title> <meta name="description" content=""> <meta name="keywords" content=""> <script src="./jquery-2.2.1.min.js"></script> <script src="./async.min.js"></script> <style> * { padding: 0; margin: 0; box-sizing: border-box; } .container { width: 500px; margin: 30px auto; text-align: center; } .result { border: 1px solid #9E9E9E; height: 300px; overflow: auto; margin-bottom: 30px; } .btn { color: white; font-weight: 300; font-size: 16px; background-color: #7B72E9; border-color: #7B72E9; text-decoration: none; text-align: center; line-height: 40px; height: 40px; padding: 0 40px; margin: 0; border-radius: 200px; display: inline-block; appearance: none; cursor: pointer; border: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; -webkit-transition-property: all; transition-property: all; -webkit-transition-duration: .3s; transition-duration: .3s; } </style> </head> <body> <p class="container"> <p class="result"> </p> <p class="btn" id="scratch"> 抓取 </p> </p> <script> $(function () { // create a queue object with concurrency 2 var q = async.queue(function(task, callback) { console.log('hello ' + task.name); callback('some thing wrong'); }, 2); // assign a callback q.drain = function() { console.log('all items have been processed'); }; $('#scratch').click(function() { // add some items to the queue q.push({name: 'foo'}, function(err) { if(err) { console.log(err); } else { console.log('finished processing foo'); } }); q.push({name: 'bar'}, function (err) { if(err) { console.log(err); q.kill(); } else { console.log('finished processing bar'); } }); q.push({name: 'meng'}, function (err) { if(err) { console.log(err); } else { console.log('finished processing meng'); } }); }); }); </script> </body> </html>
直接给你api。或许你会找到你要的答案,看看kill()做的事情
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
代码如下:
直接给你api。或许你会找到你要的答案,看看kill()做的事情