Thông thường bạn muốn định nghĩa một chức năng chính để chạy, thường được gọi là
DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
0, sau đó bạn muốn nó chạy khi cửa sổ tải xongSử dụng document.body.onload = mainProcedure;
sẽ thực hiện thủ thuật
Đoạn mã sau là từ một tập lệnh trống, sẵn sàng hoạt động
// this is the main function
function mainProcedure [] {
// your code goes inside here
}
//INPUT: start mainProcedure[] when the body of the page is finished loading
document.body.onload = mainProcedure;
Ba cách cơ bản để xuất thông tin văn bản cho người dùng
Tin nhắn bật lên với DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
2
DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
Muốn làm phiền người dùng của bạn?
Nhưng vẫn có nhiều lúc bạn muốn bật một cửa sổ, chẳng hạn như để thông báo hoặc để giúp bạn khắc phục sự cố chương trình của mình
Để thực hiện việc này, hãy thêm dòng alert["example message"];
bên trong
DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
4Bí mật gửi tin nhắn đến bảng điều khiển dành cho nhà phát triển với DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
5
DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
Đôi khi bạn muốn nhắn tin bí mật cho chính mình. Trong hầu hết các trình duyệt, có bảng điều khiển dành cho nhà phát triển hiển thị lỗi và thông tin khác. Nó thường có thể được mở bằng cách nhấn ctrlshiftJ trên bàn phím
Nếu bạn thêm
DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
6 vào DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
4, thông báo sẽ xuất hiện trong bảng điều khiểnBạn sẽ thấy rằng bảng điều khiển dành cho nhà phát triển là điều cần thiết để săn tìm lỗi
VÀ QUAN TRỌNG NHẤT. Chèn văn bản vào phần tử HTML với DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
8
DOCTYPE html>
A basic Javascript Program
Basic text output methods
The following paragraph is empty at the beginning of the program:
// OUTPUT: show an alert, a log, and in insertion
function mainProcedure [] {
// make an alert message pop up
alert[ "Hello - this is an alert[]" ];
// send a hidden message to the developer console
// check the console out with cntl-shift-J
console.log[ "Hey! I'm in the console.log[]!" ];
var newText = "I'm now inside the empty paragraph";
// insert text inside an HTML element
document.getElementById[ "emptyId" ].innerHTML = newText;
}
//INPUT: start mainProcedure when the page finishes loading
document.body. title = mainProcedure;
Hầu hết thời gian bạn gửi văn bản cho người dùng, bạn sẽ chèn một thông báo bên trong một thành phần trên trang web của mình
Bạn có thể đưa HTML vào cảnh báo JavaScript không?
Làm cách nào để có được văn bản InternalHTML trong JavaScript?
- element with the id menu using the getElementById[] method..
- element using the createElement[] and appendChild[] methods..
- element using the innerHTML property of the
- element..