This article explains some common techniques for beginners of JavaScript. Share it for your reference. The details are as follows:
1. Javascript program storage location
In the HTML <body></body>
In the HTML <head></head>
*.js file
2. Standard format
Put it in <body></body> in HTML, start executing Javascript when the browser loads into the Body part.
<html><head></head><body><script type="text/javascript">. . . . . . </script></body></html>
Put between the <head></head> of HTML, it is generally used to trigger user events
<html><head><script type="text/javascript">. . . . . . </script></head><body></body></html>
Some js methods that can be shared or others can avoid causing duplication of code. You can put js into *.js files and introduce them in html.
<html><head><script src="filepath/*.js"/></script></head><body></body></html>
3. Common Events Text Box Focus Events
onblur: Lost focus event
onfocus: Get focus events
onchange: Text box text change event
onselect: Select text box text event
<input type="text" value="test text!" onfocus="if(value=='test text!') {value=''}" onblur="if(value=='') {value='test text!'}" /><!-- The initial value is test text! After obtaining focus, it is determined that the user has no input. When setting the text box empty and losing focus, it is determined to be empty. Set the default value-->I hope this article will be helpful to everyone's learning JavaScript programming.