隐藏函数似乎不能在jQuery Mobile中工作

Hide function doesn't seem to be working in jQuery Mobile

本文关键字:jQuery Mobile 工作 不能 函数 隐藏      更新时间:2023-09-26

我有一个使用jQuery mobile创建的小型移动应用程序。重点是,我有一个div,有3个按钮,还有其他一些东西。如果用户正在工作的设备是Windows(意思是WP),我希望该div上的三个按钮被隐藏。它们的定义如下:

<div id="finalPage" data-role="page" data-add-back-btn="false">
            <div data-role="header" data-position="fixed" data-tap-toggle="false">
                <h1>Result</h1>
            </div>
            <div data-role="content">
                 <button id="fbPost">Facebook</button>
                 <button id="twitterPost">Twitter</button>
                 <button id="g+Post">Google+</button>
            </div>
</div>
在JS端,我有这样的代码:
document.addEventListener("deviceready", WPshare, false);
function WPshare() {
    if (navigator.userAgent.indexOf('Windows') > -1) {
        console.log("The device is Windows Phone!");
        $("#fbPost").hide();
        $("#twitterPost").hide();
        $("#g+Post").hide();
    }
}

关键是它似乎不起作用。当用户打开带有id"finalPage"的页面时,我希望这三个按钮被隐藏(不可见,不可点击)。还请注意,在WP设备上执行console.log行。只有按钮没有被隐藏。有什么办法吗?

试试这个:

现场演示

JQuery

    if($('#finalPage').length != 0){
        console.log('final is found');
        $("#fbPost").closest('div').hide();
        console.log($("#fbPost"));
    }