A common technique for javascript beginners

  • 2020-03-30 03:50:43
  • OfStack

This article illustrates some of the techniques commonly used by javascript beginners. Share with you for your reference. The details are as follows:

One, Javascript program storage location

HTML < Body> < / body> inside
HTML < Head> < / head> inside
*.js file inside

Standard format

Put in HTML < Body> < / body> Inside, the Javascript is executed when the browser loads into the Body section


<html>
<head></head>
<body>
<script type="text/javascript">
 . 
</script>
</body>
</html>

Put in HTML < Head> < / head> Between, generally used in user event triggers


<html>
<head>
<script type="text/javascript">
 . 
</script>
</head>
<body></body>
</html>

There are common js methods or other methods that you can use to avoid code duplication. You can put js in a *.js file and introduce it in HTML


<html>
<head>
<script src="filepath/*.js"/></script>
</head>
<body>
</body>
</html>

Three, commonly used events text box focus events

Onblur: events that lose focus

Onfocus: getting focus events

Onchange: text box text changes events

Onselect: selects the textbox text event


<input type="text" value="test text!" onfocus="if(value=='test text!') {value=''}" onblur="if(value=='') {value='test text!'}" />
<!--  The initial value for the test text!  After gaining focus, the user is judged to have no input and the text box is left blank   Set the default value when the judgment is null when the focus is lost  -->


Related articles: