<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>缓存数组的长度</title>
<style>
p{font-size:40px;}
</style>
</head>
<body>
<a href="javascript:void(0);">触发未缓存的操作</a>
<a href="javascript:void(0);">触发已缓存的操作</a>
<script>
window.onload=function(){
//随机生成若干个div,并设置初始样式
for(var i=0;i<5000;i++){
var creat=document.createElement("div");
document.body.appendChild(creat);
changefn(creat,i,{
widthz:"100px",
heightz:"14px",
colorz:"green",
mtz:"1px"
})
}
//获取生成的div
var divarra=document.getElementsByTagName("div"),
len=divarra.length-1,
btn=document.getElementsByTagName("a");
btn[0].onclick=function(){
testtime(divarra);
}
btn[1].onclick=function(){
testtime0(divarra);
}
//主函数功能,根据bz标致变量的值来走缓存数组长度也没有缓存数据长度
function testtime(divarr){
var oldtime=new Date().getTime(),
nexttime=0;
for(var i=0;i<divarr.length;i++){
changefn(divarr[i],"没缓存",{
widthz:"110px",
heightz:"16px",
colorz:"red",
mtz:"2px"
})
if(i===len){
nexttime=new Date().getTime();
console.log(oldtime,nexttime,nexttime-oldtime,"未缓存")
}
}
}
function testtime0(divarr){
var oldtime=new Date().getTime(),
nexttime=0;
for(var j=0;j<=len;j++){
changefn(divarr[j],"已绑存",{
widthz:"120px",
heightz:"18px",
colorz:"blue",
mtz:"3px"
})
if(j===len){
nexttime=new Date().getTime();
console.log(oldtime,nexttime,nexttime-oldtime,"有缓存")
}
}
}
//动态改变属性
function changefn(obj,index,josnz){
obj.innerHTML=index;
obj.style.width=josnz.widthz;
obj.style.height=josnz.heightz;
obj.style.background=josnz.colorz;
obj.style.marginTop=josnz.mtz;
}
}
</script>
</body>
</html>
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |