Home >Web Front-end >JS Tutorial >js object-oriented example explanation

js object-oriented example explanation

小云云
小云云Original
2018-03-14 16:55:551117browse

We have shared a lot of knowledge about js object-oriented with you. This article mainly shares with you the explanation of js object-oriented examples, hoping to help everyone.

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
</head>
<body>
	<script type="text/javascript">
		function people(name,age){
			this.name = name;
			this.age = age;
		}
		son = new people("leo",30);
		document.write("name : "+son.name+" , age : "+son.age);
	</script>
</body>
</html>

1) String: The string can use single quotes or double quotes

1 Find the string in the string: indexOf() There is a return position (starting at 0), if there is no return - 1

2 Content matching: match()

3 Replacement content: replace("original","change")

4 String case conversion toUpperCase()/ toLowerCase()

5 Convert string to array split()

Example:

var str1 = "hello oo";
var s = str1.split(" ");
document.write(s[1]);

2) Date

var Date = new Date() ;

document.write(date);

getFullYear() Get the current year

getTime() Get the milliseconds

setFullYear() Set the time

getHours() getMinutes() getSeconds()

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
</head>
<body onload="startTime()">
	<script type="text/javascript">
		function startTime(){
			var today = new Date();
			var h = today.getHours();
			var m = today.getMinutes();
			var s = today.getSeconds();
			m = checkTime(m);
			s = checkTime(s);
			document.getElementById("time").innerHTML = h+" : "+m+" : "+s;
			t = setTimeout(function(){
				startTime();
			},1000);
		}
		
		function checkTime(i){
			if(i<10){
				i="0"+i;
			}
			return i;
		}
	</script>
	<p id="time"></p>
</body>
</html>

Related recommendations:

JS object-oriented usage examples

js Detailed explanation of object-oriented inheritance knowledge

Detailed explanation of JS object-oriented programming

The above is the detailed content of js object-oriented example explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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