下面列出了3种函数(它们已被最小化,因此可能很难阅读)-i0,t0和is.
I have 3 functions (they are minimalized so they might be difficult to read) listed below - i0, t0, and is.
is()和t0()都通过此行从DOM中提取数据
is() and t0() both pull data from the DOM with this line
var c=document.forms[a].elements;最好从i0()中的DOM中提取数据,然后将其传递给is()和t0()吗?
would it be better to pull the data from the DOM in i0(), and then pass it to is() and t0()?
那样,我只会从DOM中提取一次数据,但是随后我需要一个额外的变量来存储它,并将其传递给两个函数.
That way I would only pull data from the DOM once, but then I would need an extra variable to store it in an pass it to the two functions.
i0():
function i0() { if(t0()) { var a=is('f0'); s0('bi0.php',a,s2); } }t0:
function t0() { var a=document.forms['f0'].elements; a1="Please enter your credentials"; a2="That email is not registered"; a3="Incorrect credentials - Reset your password?"; if(c0(a,a1,'fb1')&&c2(a[1],a2,'fb1')&&c3(a[2],a3,'fb1')) { return 1; } else { return 0; } }is():
function is(a) { var b=''; var c=document.forms[a].elements; for(i=0;i<c.length;i++) { if(c[i].name) { if(c[i].type=='checkbox'&&c[i].checked==false) { b+=c[i].name+"=NULL&"; } else { b+=c[i].name+"="+c[i].value+"&"; } } } b=b.slice(0,-1); return b; }推荐答案
function i0(a){ t0() && (a=is('f0'), s0('bi0.php', a, s2)); // just so I can use the comma like this } // or function i0(){ t0() && s0('bio.php', is('f0'), s2); } function t0(){ var a = document.forms['f0'].elements, a1 = "Please enter your credentials", a2 = "That email is not registered", a3 = "Incorrect credentials - Reset your password?"; return +( c0(a,a1,'fb1') && c2(a[1],a2,'fb1') && c3(a[2],a3,'fb1') ); } function is(a){ var b = '', c = document.forms[a].elements; for( var i=0, l=c.length; i<l; i++ ){ c[i].name ? c[i].type == 'checkbox' && !c[i].checked && b += c[i].name + '=NULL&' : b += c[i].name + '=' + c[i].value + '&'; } return ( b = b.slice(0, -1) ); }
回答您的实际问题,是的,对document.forms['f0'].elements进行一次选择将使某些浏览器中的 速度更快,但是我怀疑这是微优化由于使用了哈希查询功能,因此只能在旧版浏览器(IE6)中更快.
to answer your actual question, yes doing a single select on document.forms['f0'].elements will make things slightly faster in some browsers, but it's a micro-optimization that I suspect will only be faster in old browsers (IE6) due to the hash-lookup.
更多推荐
我可以优化这些功能吗?
发布评论