欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用js實(shí)現(xiàn)計(jì)算代碼行數(shù)的簡(jiǎn)單方法附代碼

 更新時(shí)間:2007年08月13日 19:59:54   作者:  
一段代碼可能有幾十行,上千個(gè)字符,統(tǒng)計(jì)其行數(shù)可以先把代碼字符串化為數(shù)組,再返回該數(shù)組的長(zhǎng)度即可。
傳統(tǒng)做法:

<textarea name="abc">
123456
789
</textarea>
<script type="text/javascript">
var counter = 0;
var str = abc.value;
for(i=0; i<str.length; i++)
{
    if(str.substr(i,1)=="\n")
    counter +=1;
}
alert(counter);
</script>
轉(zhuǎn)為數(shù)組后效率就高了很多:

<textarea name="abc">
123456
789
</textarea>
<script type="text/javascript">
  alert(abc.value.split("\n").length)
</script>
<textarea name="abc" style="width:480px; height:220px;">
system.println("hello world!")
alert("hello world!");
messagebox_ok("hello world")
msgbox("hello world!")
</textarea>
<script type="text/javascript">
  alert("代碼總行數(shù):"+(abc.value.split("\n").length-1).toString())
</script>

相關(guān)文章

最新評(píng)論