javascript - 有没有一种在 JQuery 中切换选项卡的方法?

标签 javascript jquery google-chrome google-chrome-extension

首先我想在我忘记之前给你链接。

http://www.roblox.com/User.aspx?ID=1

页面底部有多个选项卡。 (装备、帽子、面孔、包裹等)

function checkForHat() {
    $.get (
        'http://www.roblox.com/User.aspx?ID=1',

        function parse(data) {
            var hatid1 = $(data).find('#ctl00_cphRoblox_rbxUserAssetsPane_UserAssetsDataList_ctl00_AssetThumbnailHyperLink');
            var hatidtitle1 = hatid1.attr('title');
            var hatidhref1 = "http://www.roblox.com" + hatid1.attr('href');
            var hatidpi1 = $(hatid1).find('img')
            var hatidpic1 = hatidpi1.attr('src')
            hatLink1 = hatidhref1;
            hatTitle1 = hatidtitle1;
            hatPic1 = hatidpic1;
            var hatid2 = $(data).find('#ctl00_cphRoblox_rbxUserAssetsPane_UserAssetsDataList_ctl01_AssetThumbnailHyperLink');
            var hatidtitle2 = hatid2.attr('title');
            var hatidhref2 = "http://www.roblox.com" + hatid2.attr('href');
            var hatidpi2 = $(hatid2).find('img')
            var hatidpic2 = hatidpi2.attr('src')
            hatLink2 = hatidhref2;
            hatTitle2 = hatidtitle2;
            hatPic2 = hatidpic2;
            var hatid3 = $(data).find('#ctl00_cphRoblox_rbxUserAssetsPane_UserAssetsDataList_ctl02_AssetThumbnailHyperLink');
            var hatidtitle3 = hatid3.attr('title');
            var hatidhref3 = "http://www.roblox.com" + hatid3.attr('href');
            var hatidpi3 = $(hatid3).find('img')
            var hatidpic3 = hatidpi3.attr('src')
            hatLink3 = hatidhref3;
            hatTitle3 = hatidtitle3;
            hatPic3 = hatidpic3;
            if (hatLink3 != null && hatTitle3 != null && hatPic3 != null) {
                checkIfNew3();
            }
            if (hatLink2 != null && hatTitle2 != null && hatPic2 != null) {
                checkIfNew2();
            }
            if (hatLink1 != null && hatTitle1 != null && hatPic1 != null) {
                checkIfNew1();
            }
        }
    );
};

当然,有些变量已经在代码的前面调用过了。

现在我的问题是如何使用 JQuery 更改选项卡。就像我说的那样,标签位于底部。

这个答案开始变得至关重要,因为我有很多要求升级它所在的 chrome 扩展程序的请求。

谢谢。

最佳答案

似乎用于执行选项卡切换的 javascript 保存在 href 属性中。您可以对该方法执行 eval。

//this will click the shirts tab     
eval($('#ctl00_cphRoblox_rbxUserAssetsPane_AssetCategoryRepeater_ctl05_AssetCategorySelector').attr('href'))

如果你想要更强大的东西,那么:

$shirtElem = $('#assetsMenu a').filter( function() {
     if ($(this).html() == 'Shirts') return true;
});
eval($shirtElem.attr('href'));

我都不喜欢,但这看起来像是自动生成的 visual studio 代码,这意味着它会很难看并且很难使用 =)。我还假设您对源没有任何控制权,否则这会简单得多。

关于javascript - 有没有一种在 JQuery 中切换选项卡的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8951118/

相关文章:

附加为类属性时,Javascript 字符串按空格分隔

javascript - 在 HTML Canvas 上绘制重叠内容时如何重置透明度?

javascript - 如何创建 'dot function' ? (js 对象?)

javascript - 自动调整div的大小

javascript - 设置 cookie 一天后过期

javascript - Codeigniter 上的动态相关下拉列表国家和州

python - 如何在 Selenium Webdriver Python 3 中使用 Chrome 配置文件

php - JS/jQuery/PHP : trying to generate an URL using PHP variables

javascript - 为什么 Service Worker 不在 Chrome for Android 上运行?

google-chrome - -webkit-font-smoothing 是否仅适用于 Mac 浏览器,不适用于 Windows?