The examples in this article explain some common techniques used by JavaScript beginners. Share it with everyone for your reference. The details are as follows:
1. Javascript program storage location
In HTML
2. Standard format
Put it inside the
of HTML. When the browser loads the Body part, it will start executing Javascript<html> <head></head> <body> <script type="text/javascript"> 。。。。。。 </script> </body> </html>
is placed between
in HTML, generally used to trigger user events<html> <head> <script type="text/javascript"> 。。。。。。 </script> </head> <body></body> </html>
For some shared js methods or other ways to avoid code duplication, you can put the js into the *.js file and introduce it into the 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 event
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!'}" /> <!-- 初始值为test text! 获得焦点后判断用户无输入将文本框设空 失去焦点时判断为空时设置默认值 -->
I hope this article will be helpful to everyone’s learning of javascript programming.