Tôi có những điều sau đây để đọc một tệp cục bộ và hiển thị,
function readfile[] {
document.getElementById['iframe'].contentDocument.body.firstChild.innerHTML;
}
Nhưng ở đây bạn có thể thấy tôi đã đưa ra đường dẫn tệp là 'txt2.txt', nhưng tôi không muốn đặt tên tệp trước đó, thay vào đó tôi muốn tải tệp và hiển thị nội dung của nó bằng cách sử dụng đầu vào loại = "tệp" , Làm thế nào để làm điều này mà không cần sử dụng Ajax?
Hỏi ngày 25 tháng 9 năm 2013 lúc 23:45Sep 25, 2013 at 23:45
Animated Buttons
Modal Boxes
Animations
Progress Bars
Hover Dropdowns
Click Dropdowns
Responsive Tables
Bao gồm HTML
Bao gồm HTML được thực hiện bằng cách sử dụng thuộc tính W3-Include-HTML:w3-include-html attribute:
Thí dụ
Xác định trường chọn tệp:w3-include-html="content.html">
Sử dụng Google Chrome để truy cập các tệp cục bộ cũng dễ dàng như nhấn Ctrl + O cùng một lúc. Giao diện này sẽ mở, cho phép bạn điều hướng đến bất kỳ tệp hoặc thư mục nào là cần thiết. Có một số loại tệp có thể được mở bằng Chrome. Chúng bao gồm các tệp PDF, MP3, một số tệp video và hầu hết các tệp tài liệu.
function includeHTML[] {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.getElementsByTagName["*"];
for [i = 0; i < z.length; i++] {
elmnt = z[i];
/*search for elements with
a certain atrribute:*/
file = elmnt.getAttribute["w3-include-html"];
if [file] {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest[];
xhttp.onreadystatechange = function[] {
if [this.readyState == 4] {
if [this.status == 200] {elmnt.innerHTML = this.responseText;}
if [this.status == 404] {elmnt.innerHTML = "Page not found.";}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute["w3-include-html"];
includeHTML[];
}
}
xhttp.open["GET", file, true];
xhttp.send[];
/* Exit the function: */
return;
}
}
}
Sử dụng Google Chrome để truy cập các tệp cục bộ cũng dễ dàng như nhấn Ctrl + O cùng một lúc.Giao diện này sẽ mở, cho phép bạn điều hướng đến bất kỳ tệp hoặc thư mục nào là cần thiết.Có một số loại tệp có thể được mở bằng Chrome.Chúng bao gồm các tệp PDF, MP3, một số tệp video và hầu hết các tệp tài liệu.pressing Ctrl + O at the same time. This interface will open, allowing you to navigate to whichever file or folder is needed. There are several types of files which can be opened using Chrome. These include pdf, mp3 files, some video files and most document files.