Is there a way to set a javascript variable as the content of another HTML page?
有没有办法将javascript变量设置为另一个HTML页面的内容?
I tried:
var X = $(http://www.website.com/home).html()
var X = $(http://www.website.com/home).html()
but it didn't return anything.... Even tho it explains the idea... so... can anyone tell me how to do so please? Also the content of a certain id
or class
in that website, something like:
但它没有返回任何东西......即使它解释了这个想法......所以......有人能告诉我怎么做吗?也是该网站中某个id或类的内容,例如:
var X=$(http://www.website.com/home "#id").html()
var X = $(http://www.website.com/home“#id”)。html()
It would really help me, thanks in advance!
这对我很有帮助,在此先感谢!
1 个解决方案
#1
7
It sounds like you're looking for this:
听起来你正在寻找这个:
$.get('otherPage.html').then(function(responseData) {
//responseData is the contents of the other page. Do whatever you want with it.
$('#someElem').append(responseData);
});
现场演示(点击)。
$.get()
is a shorthand method for jQuery's $.ajax()
. http://api.jquery.com/jquery.ajax/
$ .get()是jQuery的$ .ajax()的简写方法。 http://api.jquery.com/jquery.ajax/
#1
7
It sounds like you're looking for this:
听起来你正在寻找这个:
$.get('otherPage.html').then(function(responseData) {
//responseData is the contents of the other page. Do whatever you want with it.
$('#someElem').append(responseData);
});
现场演示(点击)。
$.get()
is a shorthand method for jQuery's $.ajax()
. http://api.jquery.com/jquery.ajax/
$ .get()是jQuery的$ .ajax()的简写方法。 http://api.jquery.com/jquery.ajax/