Created
October 22, 2017 15:13
-
-
Save hjzheng/be706fe9766f4f4b329f151c1c672d7a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/focehuhozi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>使用代理合并 http 请求</title> | |
</head> | |
<body> | |
<input type="checkbox" id="1"/> | |
<input type="checkbox" id="2"/> | |
<input type="checkbox" id="3"/> | |
<input type="checkbox" id="4"/> | |
<input type="checkbox" id="5"/> | |
<input type="checkbox" id="6"/> | |
<input type="checkbox" id="7"/> | |
<input type="checkbox" id="8"/> | |
<input type="checkbox" id="9"/> | |
<input type="checkbox" id="10"/> | |
<script id="jsbin-javascript"> | |
function sendMessage(somebody) { | |
console.log('send Message to ' + somebody); | |
} | |
var proxySendMessage = function() { | |
var cache = []; | |
var timeout = null; | |
return function(somebody) { | |
cache.push(somebody); | |
if(timeout) { | |
return; | |
} | |
timeout = setTimeout(function(){ | |
sendMessage(cache.join(',')); | |
clearTimeout(timeout); | |
timeout = null; | |
cache.length = 0; | |
}, 2000); | |
} | |
}(); | |
var checkboxes = document.getElementsByTagName('input'); | |
for(var i=0, len = checkboxes.length; i < len; i++) { | |
checkboxes[i].onclick = function(){ | |
if(this.checked === true) { | |
proxySendMessage(this.id); | |
} | |
} | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function sendMessage(somebody) { | |
console.log('send Message to ' + somebody); | |
} | |
var proxySendMessage = function() { | |
var cache = []; | |
var timeout = null; | |
return function(somebody) { | |
cache.push(somebody); | |
if(timeout) { | |
return; | |
} | |
timeout = setTimeout(function(){ | |
sendMessage(cache.join(',')); | |
clearTimeout(timeout); | |
timeout = null; | |
cache.length = 0; | |
}, 2000); | |
} | |
}(); | |
var checkboxes = document.getElementsByTagName('input'); | |
for(var i=0, len = checkboxes.length; i < len; i++) { | |
checkboxes[i].onclick = function(){ | |
if(this.checked === true) { | |
proxySendMessage(this.id); | |
} | |
} | |
}</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendMessage(somebody) { | |
console.log('send Message to ' + somebody); | |
} | |
var proxySendMessage = function() { | |
var cache = []; | |
var timeout = null; | |
return function(somebody) { | |
cache.push(somebody); | |
if(timeout) { | |
return; | |
} | |
timeout = setTimeout(function(){ | |
sendMessage(cache.join(',')); | |
clearTimeout(timeout); | |
timeout = null; | |
cache.length = 0; | |
}, 2000); | |
} | |
}(); | |
var checkboxes = document.getElementsByTagName('input'); | |
for(var i=0, len = checkboxes.length; i < len; i++) { | |
checkboxes[i].onclick = function(){ | |
if(this.checked === true) { | |
proxySendMessage(this.id); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment