Когда я отлаживал код, я обычно проверяю выполнение кода JS, используя Alert в блоке кода. Сегодня я также видел друга, использующего функцию console.log для распечатки функций, переменных, объектов и использования консоли. Log записан ниже. Конкретный синтаксис:
console.log ("value:", fn);Console.log () может выходить выходные переменные, функции, массивы, объекты и т. Д.
<html> <head> <title> This Keyword_function Call </title> <meta http-equiv = "content-type" content = "text/html; charset = gb2312"> </head> <body> <input type = "text" id = "test1" = "firstname" value = "/"/> <input type "=" text-id. 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);/ ** print object **/ testobj.firstname (); testobj.lastname (); </script> </html>