1. I read a tutorial case of a marquee, and after a while I wrote a simple marquee. The problems encountered in the process are hereby recorded.
The code is as follows:
<! DOCTYPE Html>"Content-type"Content="text/html;charset=gb2312"> <title> Jane Burrow tube after set </title> 'Button'Value='Stop Titleloop'Id='Stoploop'/><script src='C:\Users\wujy1\Desktop\html\js\jquery-3.1.1.min.js'></script><script>function Titleloop () {//implementing a title Loop vartitle=$ ('title'). text (); FirstWord=title[0];//Save the first character of a stringTitle=title.substring (1);//intercepts the first character of a string /*Document.title=title+firstword; Use this method to compare memory consumption. For example: var lang = "Java"; Lang = lang + "Script"; Start by creating a new string that can hold 10 characters, then populate the string with "Java" and "script", and the final step is to destroy the original string "Java" and "script", because these two strings are useless. However, in a lower version of the browser (such as IE6), the string stitching speed is a process that consumes a performance. */ varArry=array (Title,firstword);//position the new string and the first character as an array (note the order) and use the Join method to stitch togetherTitle=arry.join (""); $('title'). Text (Title);//Change title Content } varLoop=setinterval ("Titleloop ()", -);//Enable loops$('#stoploop'). Click (function () {clearinterval (loop);});//End Loop</script></body>Problem:
When I want to end the loop, the following code is not used to end the process:
$ (' #stoploop '). Click (function() {Clearinterval (SetInterval ("Titleloop ()", 500))
View clearinterval Description: The parameter of the Clearinterval () method must be the ID value returned by SetInterval ().
Use this time:
var loop=setinterval ("Titleloop ()", +); Console.log (loop); #返回1console. Log (SetInterval ("Titleloop ()")#返回2console. Log (SetInterval ("Titleloop ()", 500)) # Returns 3
So the loop must be assigned to the variable, and then the loop is closed.
At this point, it is assumed that whenever a setinterval () is defined, his ID value is incremented by 1. Verify that:
JavaScript Racing Lights