為什么數(shù)組長度結(jié)果跑前面去了
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html?xmlns="http://www.w3.org/1999/xhtml"> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> <title>數(shù)組長度</title> <script?language="javascript"> ?var?acv=new?Array(65,90,88,98); ?document.write("數(shù)組的長度是:"+?document.write(acv.length)); </script> </head> <body> </body> </html>
結(jié)果為啥是?4數(shù)組的長度是:undefined 而不是?數(shù)組的長度是: ?4 ?undefined
2016-07-18
第9行 document.write("數(shù)組的長度是:"+?document.write(acv.length));
改為:
document.write("數(shù)組的長度是:"+acv.length);
又或者:
document.write("數(shù)組的長度是:");
document.write(acv.length); 你這用法有問題....沒見過document.write里面嵌套document.write
2016-09-17
我是這樣理解的,逆向來看,程序會先執(zhí)行document.write(mynum.length)//輸出4。再執(zhí)行document.write()//輸出undefined。再執(zhí)行document.write("數(shù)組的長度是:"+undefined);至于為什么變成document.write().就不知道了??梢杂眠@個document.write(document.write(4+"<br/>"));更加清楚。
2016-07-18
重復的document.write
2016-07-18
先執(zhí)行的括號里的?document.write,所以先輸出4,把后面那個document.write去掉改成document.write("數(shù)組的長度是:"+acv.length);
2016-07-18
先執(zhí)行的括號里的?document.write所以先輸出4,改成document.write("數(shù)組的長度是:"+ (acv.length)就行了;
2016-07-18
在document.write("數(shù)組的長度是:"+?document.write(acv.length));把后面那個document.write去掉改成document.write("數(shù)組的長度是:"+acv.length);試試