有几个函数必须得到 dom $$('.box')[0] ,我不想让 box 成为一个 glabal var,我不想让 js 每次都寻找 dom . 当用户不运行这些功能时,我不想运行 $$('.box')[0] 。如何存储盒子变量?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js"></script>
<script type="text/javascript">
/* -------
there are several function will have to get the dom $$('.box')[0] ,
I don't want to let box to be a glabal var, and I don't want to let js seek the
dom every time . and I don't want to run $$('.box')[0] when user not run these functions.
how to store the box var?
------- */
function a(){
var box = $$('.box')[0];
//...
}
function b(){
var box = $$('.box')[0];
//...
}
//...
</script>
<div class="box"></div>