Home > Web Front-end > JS Tutorial > body text

Common skills for javascript beginners_javascript skills

WBOY
Release: 2016-05-16 16:38:01
Original
1395 people have browsed it

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
HTML


*.js file inside

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>

Copy after login

is placed between

in HTML, generally used to trigger user events

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

Copy after login

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>

Copy after login

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! 获得焦点后判断用户无输入将文本框设空 失去焦点时判断为空时设置默认值 -->

Copy after login

I hope this article will be helpful to everyone’s learning of javascript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template