A piece of code may have dozens of lines or thousands of characters. To count the number of lines, you can first convert the code string into an array, and then return the length of the array.
Traditional approach:
After converting to an array, the efficiency is much higher:
msgbox("hello world!")
<script> <BR>var counter = 0; <BR>var str = abc.value; <BR>for(i=0; i<str.length; i++) <BR>{ <BR> if(str.substr(i,1)=="\n") <BR> counter +=1; <BR>} <BR>alert(counter); <BR></script><script> <BR> alert(abc.value.split("\n").length) <BR></script> <script> <BR> alert("代码总行数:"+(abc.value.split("\n").length-1).toString()) <BR></script>