Instructions: Use the write method (function) of the document object to create.
Instructions: Use the card to create a button and add the onClick attribute = "
Create 2 elements as in example 2 with HTML tags, when the user clicks on the Welcome button, displays the content contained in the text named msg .
Instructions: To get the value of an HTML element, you write
For example: msg.value gives us the value of the text named msg.
Create 2 elements as example 2, when the user presses the button, call a function named HienThi, the function displays the function of displaying the content in the text named msg above.
Instructions : In the button to create the button, you set the onClick attribute = "
Requirements: Display the date and time of the computer system when the Web page is loaded. The information displayed looks like this:
Instructions: Use the Date object and use the functions to get things, days, months and years to print information to the screen. Pay attention to the functions of the month and day of the week missing a unit.
Requirements: Displays the Time and Minute in the title bar of the window when the Web page is loaded.
Instructions: The value displayed in the title bar of the website is stored in the title attribute of the document object, so to display the information in the title bar, you need to write: document.title =
Requirements: For users to enter their birth year, then display the corresponding age.
Instructions: Use the Date object to get the current year. Age will be equal to the current year minus the year of birth.
Instructions: Use the do . while loop to request re-entry if the year of birth> current year.
Requirements: Write a script for users to enter an integer. If the user enters the number 1, open the website https://quantangang.com, if entering the number 2, then open the page https://download.com.vn, if entering the number 3, open the page https://vndoc.com, If you enter a number other than 1, 2 or 3, open the page https://meta.vn.
Instructions: To open any Web page in the current window, write the following:
window.open ("Address of the page to open").
For example: window.open (https://quantrimang.com ) to open the VNN homepage in the current window.
So, to solve the problem of the above problem, you need to let the user enter a number and use the switch structure to check and open the corresponding website.
Mở trang web bằng hàm open của đối tượng window.
Requirement: Let the user enter the list of a class's name, then arrange alphabetically and then display the sorted list on the screen, one on each line.
Instructions: Use the for loop to allow the name list to be entered and Save the list into an array, then use the sort method of the array object to sort, then use the for . loop to print the element in the list.
Sắp xếp mảng
Comment: If you want to descend in the descending direction, after the sort you call the reverse function.
Requirements: Create a button (Button) with name = "DangKy", value = "Register". When the user clicks on this button, the message is "Register for E-Mail service".
- Onclick = "alert ('Hello world';"
- OnClick = "var x, y; x = 10; y = 20; alert ('Total is:' + (x + y));"
- OnClick = "var Tuoi; Tuoi = txtTuoi.value; KiemTra (Tuoi);"
- OnClick = "KiemTra ();"
According to the above example, when the user clicks:
1: Execute the alert command ('Hello world')
5: Make a call to the function KiemTra ().
Create a button with name = ReplaceMauNen, value = "Change background color". When users click on this button, change the background color of the Web page to "green".
Instructions: To change the background color of a Web page to color, you need to change the document attribute.bgColor = "blue". (Red is red, find: magenta, black: black, white: white, yellow: Yellow, light purple: lavender). Thus, this statement will be placed in the onClick section as follows:
Thay mau nen bang click chuot
Change the background color using the document object
Requirements: Create a text box named HoTen. A button named HienThi, value = "Display". When the user clicks on HienThi button, displays the text in that text box with the alert function.
Instructions: To get the value of a certain HTML element, we write
For example: - Hoten.value, DangKy.value, GioiTinh.value, Password.value etc .
Đọc giá trị trong hộp text
Type the text in the text box and click the Show button
Requirements: Create three text boxes in turn named SoHang1, SoHang2, KetQua and a button named TinhTong, to perform the total calculation. When the user enters two terms in the SoHang1 and SoHang2 boxes, then click the TinhTong button, the total result will be saved in the KetQua text box.
Instructions: To change the value of a certain attribute of an HTML element, write the following:
Where: Element name is the value of the name attribute when you create the tag.
For example: HoTen.value = "This is new text", DangKy.value = "Sign Up now", etc.
Thay đổi giá trị của thuộc tính
Please enter the two numbers and click the Total calculation button
Note: - The value stored in the text box is always a string, so to perform the addition is correct, you need to convert the value to a number using parseFloat (Or parseInt) function as above.
- This change can be applied to other elements such as buttons, checkboxes, etc.
Requirements: Create 4 texts named respectively: MauNen, MauChu, TieuDe, TrangThai and a button named ThayDoi, value is "Change". When the user clicks the Change button, the background color, the title of the document and the status bar of the browser window will be changed with the values in the corresponding text.
Instructions: You can write as many statements in the OnClick attribute as in the previous examples, but if there are multiple commands, the program doesn't look very bright. You can then group the statements into a function and in the OnClick attribute you just call this function.
Thay đổi thuộc tính của trang Web
Enter the values and click the Change button
Comment: In the above example, when the user clicks on the Change button, CapNhat () function will be called.
Instructions: First of all, we need to determine which commands allow us to change the title of the window to "You have clicked", followed by placing the commands so that when the user clicks the mouse, it is done. take the exam as required
- The command to change the title is as follows: title = "You have clicked the mouse"
- As we know when the user clicks, the onClick event appears, so the above statement will be placed corresponding to the onClick event, as follows:
Hãy click vào nút ở dưới và quan sát tiêu đề
Instructions: At the request of the lesson, the message "You have clicked on the submit button" appears only when the user clicks the submit button, so the commands that display the message will be placed in the onclick event. of push button. The message "You have clicked on the text box" when the user clicks on the textbox, so the commands to display the message line will be placed in the onclick event of the textbox :
Hay click vao nut va textbox o duoi va quan sat tieu de
Requirements: When the user clicks on the green button, the background color of the document is blue (blue), and when the user clicks on the red button, the background color of the document is: Red (red).
Instructions: The background color attribute of the document is stored in the bgColor property of the document object. This attribute is changeable.
Create a selection list of 4 colors: red, blue, brown and lavender. When a user selects a color, the background color of the document changes accordingly.
Bạn hãy chọn màu nền: Màu đỏ Màu xanh Màu nâu Màu xanh nhạt
Số ký tự đã gõ: