字符串连接是一个代价很高的操作,最好只对较小的字符串进行连接操作,大字符串则可以使用Array的join()方法
function
getRequestBody(form)
{
var aParam = new Array();
for ( var i = 0 ;i < form.elements.length;i ++ ) {
var sParam = encodeURIComponent(form.elements[i].name);
sParam += " = " ;
sParam += encodeURIComponent(form.elements[i].value);
aParam.push(sParam);
}
return aParam.join( " & " );
}
var aParam = new Array();
for ( var i = 0 ;i < form.elements.length;i ++ ) {
var sParam = encodeURIComponent(form.elements[i].name);
sParam += " = " ;
sParam += encodeURIComponent(form.elements[i].value);
aParam.push(sParam);
}
return aParam.join( " & " );
}