【问题标题】:Windows Phone 8.1 WinJS Appbar disabled property not workingWindows Phone 8.1 WinJS Appbar 禁用属性不起作用
【发布时间】:2015-06-10 23:18:54
【问题描述】:

我正在尝试隐藏(禁用)appBar,以便它不会显示在我的应用程序的页面上。但是 disabled 属性似乎不起作用,或者我的语法已关闭。我试过像这样使用它:

<script>
    var disabled = appBar.disabled;
    appBar.disabled = disabled;
</script>

<script>
    var disabled = appBar.disabled;
    appBar.disabled = true;
</script>

但 appBar 仍然可见。在这两种情况下,我都将脚本放在 HTML 下方:

<!-- BEGINTEMPLATE: Template code for an app bar -->
<div id="appBar" data-win-control="WinJS.UI.AppBar" data-win-options="{closedDisplayMode:'minimal', disabled: false}">
    <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdAbout', label:'about...', section:'selection'}"></button>
</div>
<!-- ENDTEMPLATE -->
<div id="statusMessage"></div>

<script>
    var disabled = appBar.disabled;
    appBar.disabled = true;
</script>

我做错了什么?

【问题讨论】:

    标签: javascript html windows-phone-8.1 winjs


    【解决方案1】:

    您是否正确初始化了appBar 变量?它没有在您的代码 sn-p 中定义。试试这种方式,至少它在我的应用程序中有效。

    <script>
    (function(){
        var appBar = document.getElementById("appBar");
        if(appBar.winControl) {
            appBar.winControl.disabled = true;
        }
    }());
    </script>
    

    另外不要忘记WinJS.UI.processAll 是异步运行的,所以你的脚本不能只放在 HTML 标记之后,它只有在 AppBar 已经创建后才能工作。

    【讨论】:

    • 谢谢你,我回家试试看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多