Tôi muốn mã HTML, JavaScript đầy đủ để hiển thị dữ liệu biểu mẫu trên cùng một trang
Những gì tôi đã thử:
Kiểm tra đầu vào
function testVarable [] {var strtext = document.getEuityById ["covertone"]; document.write [strtext.value]; var strtext1 = document.getEuityById ["texttwo"]; document.write [strText1.value]; }
var strText = document.getElementById["textone"];
document.write[strText.value];
var strText1 = document.getElementById["textTWO"];
document.write[strText1.value];
}
Mã số,
function testVariable[] { var strText = document.getElementById["textone"].value; var strText1 = document.getElementById["textTWO"].value; var result = strText + ' ' + strText1; document.getElementById['spanResult'].textContent = result; } Submit
Không sử dụng Document.Write. Nếu bạn muốn thêm nội dung vào một trang, bạn cần làm việc với DOM. Google "Tạo Div JavaScript" hoặc "Tạo Span JavaScript" cho các ví dụ, về cơ bản bạn cần tạo một yếu tố có văn bản của bạn trong đó và thêm phần tử đó vào một phần của trang bạn muốn văn bản hiển thị.
Ngoài ra, div \ span bạn muốn văn bản xuất hiện tại trang và chỉ cập nhật nó
document.getElementById["myDiv"].innerHTML = strText.value;
Submithàm myfunction [] {var a, b, currdate, d, n; a = document.frm.text.value; b = a.subString [0,2]; var currdate = ngày mới [];
var a,b,currdate,d,n;
a= document.frm.text.value;
b=a.substring[0,2];
var currdate = new Date[];var currdate = currdate.getDate [] + '' + [currdate.getMonth [] + 1] + '' + chuỗi [currdate.getlyear []]. var d = ngày mới []; var n = d.getSeconds []; document.getEuityById ["popcode"]. InternalHtml = b+currdate+n;
var d = new Date[];
var n = d.getSeconds[];
document.getElementById["popcode"].innerHTML =b+currdate+n;}
Document function testVariable[] { debugger var strText = document.getElementById["txtName"].value; var strText1 = document.getElementById["txtEmail"].value; document.getElementById["p1"].innerHTML = strText; document.getElementById["p2"].innerHTML = strText1; } function showInput[] { document.getElementById['display'].innerHTML = document.getElementById["user_input"].value; } Enter a Message
Your input:DocumentRegistration Form
Name:
Email: const register = function [event] { let r_name = document.querySelector["#name"].value; let r_email = document.querySelector["#email"].value; display_name.innerHTML = r_name; display_email.innerHTML = r_email; event.preventDefault[]; };
Nội dung này, cùng với bất kỳ mã nguồn và tệp liên quan nào, được cấp phép theo giấy phép mở của Dự án Mã [CPOL]
Làm cách nào để hiển thị nội dung của cùng một trang trong HTML?
Nếu bạn muốn thêm nội dung vào một trang, bạn cần làm việc với DOM. Google "Tạo Div JavaScript" hoặc "Tạo Span JavaScript" cho các ví dụ, về cơ bản bạn cần tạo một yếu tố có văn bản của bạn trong đó và thêm phần tử đó vào một phần của trang bạn muốn văn bản hiển thị.create an element that has your text in it and add that element to the part of the page you want the text to display.Làm cách nào để hiển thị dữ liệu trong trang HTML?
JavaScript có thể "hiển thị" dữ liệu theo những cách khác nhau:..Viết vào một phần tử HTML, sử dụng InternalHTML ..Viết vào đầu ra HTML bằng document.write [] ..Viết vào một hộp cảnh báo, sử dụng window.alert [] ..Viết vào bảng điều khiển trình duyệt, sử dụng Console.log [] ..Làm cách nào để gửi dữ liệu đến cùng một trang?
Để ở trên cùng một trang khi gửi, bạn có thể bỏ trống hành động [Action = ""] vào thẻ biểu mẫu hoặc bỏ hoàn toàn.Đối với thông báo, hãy tạo một biến [$ message = "Thành công! Bạn đã nhập:". $ Input; "] và sau đó lặp lại biến tại địa điểm trong trang mà bạn muốn tin nhắn xuất hiện vớileave action empty [ action="" ] into the form tag, or leave it out altogether. For the message, create a variable [ $message = "Success! You entered: ". $input;" ] and then echo the variable at the place in the page where you want the message to appear withChủ Đề