js study

1536 ワード




Title of the document




First name:
Last name:
Username:
function Person(name, age, job){ 
	this.name = name; 
	this.age = age; 
	this.job = job; 
	this.sayName = sayName; 
} 
function sayName(){ 
	console.info(this.name); 
} 

var person1 = new Person("Nicholas", 29, "Software Engineer"); 
var person2 = new Person("Greg", 27, "Doctor"); 

person1.sayName(); //
person2.sayName(); // 

var pattern = /[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}/;

// 2)     
var math = { 
	value1: 3, 
	value2: 4, 
	sum: function() {
		return this.value1 + this.value2;
	},
	testSum: function(){ 
		return this.value1 + this.sum(); 
	} 
};

var math2 = new Object();


console.info(math.sum());
console.info(math.testSum());

//     
var edit1 = document.getElementById("fname");
edit1.value = "fighting";
var edit2 = document.getElementById("sname");
edit2.setAttribute("value", "All is well");

function changeText() {
	var btn1 = document.getElementById("submitbutton");
	btn1.value = "hello";
	var btn2 = document.getElementById("testbutton");
	btn2.value = "world";
}

function checkCookies() {
	var btn1 = document.getElementById("submitbutton");
	btn1.value = "mengxiang";
	var btn2 = document.getElementById("testbutton");
	btn2.value = "jianchi";
}