为什么它找不到元素的内部 HTML

Why isnt it finding the element's innerHTML?

本文关键字:内部 HTML 元素 找不到 为什么      更新时间:2023-09-26
function getViews(){
    $.get (
    "http://www.roblox.com/User.aspx?ID=16",
        function parse(data) {
            var userviews = $(data).find("#ctl00_cphRoblox_rbxUserStatisticsPane_lProfileViewsStatistics").html();
            alert(userviews);
        }
    );
}
getViews();

我基本上希望它做与下面一行相同的事情,除了我的 jquery 函数还有更多我没有给出,因为我知道它有效:

alert(document.getElementById('ctl00_cphRoblox_rbxUserStatisticsPane_lProfileViewsStatistics').innerHTML)

您没有提供详细信息,但我怀疑您的success回调甚至没有执行(即alert()没有触发(,因为 AJAX 请求失败。您的代码可能无法正常工作,除非它托管在 http://www.roblox.com .我可以在浏览器控制台中看到以下错误:

XMLHttpRequest 无法加载http://www.roblox.com/User.aspx?ID=16 。 访问控制允许

源不允许源http://test.local

在Firebug,Chrome和最近的IE中,您可以使用F12打开控制台。在 Firefox 中,您可以使用 Ctrl+Shift+K