Home > Web Front-end > JS Tutorial > js debugging tool console.log() method to view the execution of js code_javascript skills

js debugging tool console.log() method to view the execution of js code_javascript skills

WBOY
Release: 2016-05-16 16:40:00
Original
1316 people have browsed it

When I was debugging the code before, I usually checked the execution of the js code by using alert in the code block. Today I also saw a friend using the console.log function to print the output. Functions, variables, objects, the usage of console.log is recorded below. The specific syntax is:

console.log("值为:",fn);
Copy after login

console.log() can output variables, functions, arrays, objects, etc.

<html> 
<head> 
<title>this关键字_函数调用</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head> 
<body> 

<input type="text" id="test1" name="firstname" value="" /> 
<input type="text" id='lastname' name='lastname' value=''> 

</body> 

<script type="text/javascript"> 
var testobj = 
{ 
'id': 1, 
'content': 'test', 
'firstname': function() { 
var EleFirst= document.getElementById('test1'); 
//document.getElementById('firstname').value = "zhang"; 
//document.getElementById("test1").value = this.content; 
//document.getElementById("test1").setAttribute("value","zhang"); 
//this.content = val; 
EleFirst.setAttribute("value",this.content); 
console.log("对象的值为:",test1);//对象的值为:<input type="text" id="test1" name="firstname" value="" /> 
}, 
'lastname': function() { 
document.getElementById('lastname').value = "ying"; 
} 
}; 
console.log(testobj);/** 打印对像**/ 

testobj.firstname(); 
testobj.lastname(); 
</script> 
</html>
Copy after login
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