简体   繁体   English

隐藏功能在jQuery Mobile中似乎不起作用

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

I have a small mobile app that is created using jQuery mobile. 我有一个使用jQuery mobile创建的小型移动应用程序。 The point is that I have a div with 3 buttons, and some other stuff. 关键是我有一个带3个按钮的div,以及其他一些东西。 If the device that the user is working is Windows (meaning WP), I want the three buttons on that div to be hidden. 如果用户正在使用的设备是Windows(即WP),则我希望该div上的三个按钮被隐藏。 They are defined like this: 它们的定义如下:

<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>

On JS side I have a code like this: 在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();
    }
}

The point is that it doesn't seem to be working. 关键是它似乎不起作用。 When the user opens the page with the id "finalPage", I want those three buttons to be hidden (not visible, not clickable). 当用户打开ID为“ finalPage”的页面时,我希望这三个按钮被隐藏(不可见,不可单击)。 Please also note that on WP devices the console.log line is executed. 另请注意,在WP设备上,执行console.log行。 Only the buttons are not hidden. 只有按钮没有被隐藏。 Any idea, how to achieve it? 任何想法,如何实现呢?

Try this: 尝试这个:

Live demo 现场演示

JQuery JQuery的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM