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

时间:2014-06-14 15:58:30

标签: javascript jquery html css jquery-mobile

我有一个使用jQuery mobile创建的小型移动应用程序。关键是我有一个带有3个按钮的div,以及其他一些东西。如果用户正在使用的设备是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行。仅隐藏按钮。任何想法,如何实现它?

1 个答案:

答案 0 :(得分:0)

试试这个:

Live demo

<强> JQuery的

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