我正在創建一個Windows 8 HTML5應用程序,並實現了一個應用程序欄。當我訪問appbar.winControl時,它始終爲空。因此,如果例如我寫appbar.winControl.show()我得到一個異常,聲明winControl爲空。winjs appbar.wincontrol爲空
我做的是創建一個固定的佈局應用程序。如果沒有其他人在做什麼,我說在文檔正文中的以下標記:
<body>
<div id="appbar" data-win-control="WinJS.UI.AppBar" aria-label="Command Bar">
<button id="btnBoardSizeUp" data-win-control="WinJS.UI.AppBarCommand" data-win-options="{label:'Larger', icon:'zoomout', section:'global', tooltip:'Increase the board size'}" />
<button id="btnBoardSizeDown" data-win-control="WinJS.UI.AppBarCommand" data-win-options="{label:'Smaller', icon:'zoomin', section:'global', tooltip:'Decrease the board size'}" />
<button id="btnAbortGame" data-win-control="WinJS.UI.AppBarCommand" data-win-options="{label:'Abort', icon:'cancel', section:'selection', tooltip:'Abort the current game'}" />
</div>
<script type="text/javascript">
var appbar = document.getElementById("appbar");
var winControl = appbar.winControl;
winControl.show();
</script>
線winControl.show()產生以下錯誤:
0x800a138f - JavaScript運行錯誤:無法獲取屬性「顯示」未定義或空引用
據我所見,我已經在頁面上正確實施了appbar,所以它應該工作。任何想法出了什麼問題?
謝謝@Sushil。我無法得到第一個例子 - 而是得到一個錯誤,指出processAll函數不存在。但第二個例子完美運行,所以我的問題解決了。 –
我必須修改它。現在我可以讓兩個實例工作。我不知道爲什麼第一個例子早些時候沒有工作,但這可能是我無法識別的輸入錯誤。無論如何,再次感謝@Sushil –