Tôi đã tạo một bản ngã của phiên bản Pete giữ lại cùng một chức năng kín đáo nhưng, ngoài ra, lưu trữ một bản sao của bảng điều khiển thông thường và ghi vào nó.
(function() {
// Store a copy of the old console, but don't junk up the
// global namespace with it either. This allows console
// logging in both places.
var oldConsole = console;
// Use a pre-existing #console element or create a new one.
var newConsole = document.getElementById("console") || (function() {
var pre = document.createElement('pre');
pre.setAttribute('id', 'console');
document.body.insertBefore(pre, document.body.firstChild);
return pre;
})();
console = {
log: function (message) {
var message = ['>', message, '\n'].join(' ');
// Log to both consoles...
oldConsole.log(message);
newConsole.textContent += message;
}
};
})();
console.log("This is an unobtrusive version!");
console.log("Hello World!");
console.log("Test");
console.log("Test");
console.log("Test");
console.log("Test");
console.log("Test");
console.log("Make it scrollable!");
Bạn có thể thấy một phiên bản làm việc của nó ở đây: http://jsfiddle.net/Lanlost/7n6jka2q/
Nguồn
2016-03-04 05:26:01
Chúng tôi có thể xem một số mã không? Chỉ để tìm kiếm vấn đề. Điều này có thể từ nhiều thứ. và tìm mẫu mã tạo lỗi của bạn không dễ như vậy ^^ – JajaDrinker
Có lẽ, console.log? – snowYetis
Cửa sổ kết quả chỉ là những gì trình duyệt sẽ hiển thị. Nếu bạn đang tìm cách in nó, bạn sẽ cần phải tạo một phần tử HTML và điền nó với văn bản. Tôi cho rằng bạn không thực sự cần phải thêm một phần tử nhưng nó sẽ giống như khi bạn in tới trình duyệt. –