jQuery-获取在滚动之前不会加载的DOM元素
我试图使用jQuery访问一个HTML元素,该元素在向下滚动页面之前不会实际生成 因此,这样的代码返回niljQuery-获取在滚动之前不会加载的DOM元素,jquery,Jquery,我试图使用jQuery访问一个HTML元素,该元素在向下滚动页面之前不会实际生成 因此,这样的代码返回nil $(document).ready(function() { var city = $('.pv-entity__location').text() }); 在检索此变量之前,如何使用jQuery确保在加载时加载/滚动到底部 更新: 我试图让jQuery滚动页面,然后检索变量,但似乎不起作用。我的代码有问题吗 $(document).ready(function() {
$(document).ready(function() {
var city = $('.pv-entity__location').text()
});
在检索此变量之前,如何使用jQuery确保在加载时加载/滚动到底部
更新:
我试图让jQuery滚动页面,然后检索变量,但似乎不起作用。我的代码有问题吗
$(document).ready(function() {
$('html,body').animate({ scrollTop: 9999 }, function() {
var city = $('.pv-entity__location').text()
console.log(`Text: ${city}`)
});
});
更新2
通过这个解决方案,我需要在j
animate()
找到了解决方案,我需要在
animate()
同样的问题是在你把钱放进去之前先把钱从银行里拿出来。那里没有钱。如果它还没有生成,你就无法访问它。在它生成之前,您想对它做什么?对不起,我没有清楚地问这个问题,我将重新措辞-在检索此变量之前,如何使用jQuery确保在加载时加载/滚动到底部?该元素中的文本将用于其他内容。向我们展示滚动时加载更多内容的代码。希望在加载更多后进行检查。如果您在加载页面时立即需要它,听起来像是一个设计缺陷
$(document).ready(function() {
$('html').animate({
scrollTop: $(document).height()
}, function(){
var city = $('.pv-entity__location:first:last-child').text().trim()
console.log(`Text: ${city || "empty"}`)
});
//});
});
$(document).ready(function() {
$('html').animate({
scrollTop: $(document).height()
}, function(){
var city = $('.pv-entity__location:first:last-child').text().trim()
console.log(`Text: ${city} || "empty"}`)
});
//});
});