开发者

Load html document in javascript from text

Is it possible to load an html document into a DOM javascript object so that you can read the elements in the document? For example, if I have a file on the server开发者_如何学C Test.html. Can the page Hello.html call javascript code to load Test.html into a DOM object?

Please let me know.

Thanks


You can issue an AJAX request to the new page and get the result as HTML. Then you can bind the HTML to the DOM element.

If you can use a javascrpt library like jQuery there is a load method which loads the data from server and place the returned HTML in a DOM object.

See .load()

$('yourselector').load('Test.html', function() {
  alert('Load was performed.');
});


Using jQuery:

$("#where_to_paste").load('Test.html');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜