JQuery 不返回值?或者该方法无效

JQuery not returning value? or the method is invalid?

本文关键字:方法 无效 或者 返回值 JQuery      更新时间:2023-09-26

我现在正在开发我的网站,该网站将有一个使用Javascript和jQuery制作的API。在一个名为ROBLOX的游戏中,我试图通过玩家的ID获取玩家的用户名。唯一的问题是用户名标签没有 ID,所以我通过类获取用户名标签。

但是,当我调用innerHTMLinnerText或调用 .text() 方法时,它不会返回任何内容,但是其中有文本。有没有其他方法可以获取对象内部的文本?基本上是class > h1 > text.我不确定我是否使用了错误的方法。有人可以帮忙吗?

function My(){
    var user_id = 97423773
    var lawl = ""
    $.get("roblox.com/users/" + user_id + "/profile", function(data, success) {
        lawl = $(".profile-about-content-text", data).text()
        alert(lawl)
    });
    return lawl
}
My()

这对我来说很好用,每行末尾都添加了分号!您的URL也有点奇特,并且不以/或文件扩展名结尾

"roblox.com/users/"+user_id+"/profile/"
"roblox.com/users/"+user_id+"/profile.php"
"http://www.roblox.com/users/"+user_id+"/profile/index.php"