我试图从div #content
中获取 page1.html 中的内容$(function(){
$.get('page1.html', function(data){
console.log($("#content",data).html()); <-- console.log says undefined
});
});
Page1.html
<div id="content">
<h1>Page 1</h1>
<h2>Page 1 Content</h2>
</div>
我不确定为什么它不起作用,console.log会出现 undefined 。
答案 0 :(得分:0)
以下代码将执行此操作:
var url = 'page1.html';
$(function() {
$.get(url, function(data) {
console.log(data);
$('#content').html(data);
});
});
使用httpbin.org小提琴:http://jsfiddle.net/klenwell/kyu6g3e0/(在Chrome中测试)