Học JavaScript qua ví dụ part 41

Các từ khoá này Các từ khóa này đặc biệt hữu ích khi giao dịch với hình thức. Chúng tôi sử dụng từ này khi làm việc với các đối tượng như là một tham chiếu đến đối tượng hiện hành. Đối với hình thức có chứa nhiều đối tượng, chẳng hạn như hộp kiểm, các nút radio, và các hộp văn bản, nó được dễ dàng hơn để tham khảo các đối tượng với các từ khoá này hơn bằng cách sử dụng tên đầy đủ của nó khi gọi một hàm | JavaScript and the form Object 365 Figure The user clicked the Reset Form button. The dialog box confirms the choice before the input boxes are reset to their default values. The this Keyword The this keyword is especially helpful when dealing with forms. We used the this word when working with objects as a reference to the current object. For forms containing multiple objects such as checkboxes radio buttons and textboxes it is easier to refer to the object with the this keyword than by using its full name when calling a function. When using an event handler the this keyword always refers to the object that triggered the event. If the event is triggered from within the form tag this refers to the current form but if it is triggered by an element within the form such as an input device then it references that element. Each element has a form property that references the form in which it was created. In the following segment of an HTML document note that when the onClick event handler is triggered within the first button input type the form property is used to reference the form itself whereas in the second button the this keyword refers to the current button. FORMAT form -- The JavaScript form object input type button -- This a JavaScript element value Print Form Stuff onClick display_formval -- this keyword references the form object by using the element s form property input type button value Print Button Stuff onClick display_buttonval this -- this keyword references the current object the button form From the Library of 366 Chapter 11 Working with Forms and Input Devices EXAMPLE html head title An HTML form and the this keyword and Event Handler title script type text javascript 1 function checkForm form1 2 if Check for an empty string 3 alert Please type in your name return false else return true script head body b 4 form method post action http localhost cgi-bin onSubmit return .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.