假设我有一个页面a.html
,并且想从另一个页面<p id="name">NAME</p>
中使用它的id b.html
元素来检索文本元素的文本。
最佳答案
使用jQuery的 get
method,非常简单:
$.get('a.html', null, function(text){
alert($(text).find('#name'));
});
XHR原始请求(按受欢迎的需求):
var request = new XMLHttpRequest();
request.addEventListener("load", function(evt){
console.log(evt);
}, false);
request.open('GET', 'a.html', true),
request.send();
关于javascript - 如何使用Javascript访问其他页面的元素?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12899047/