簡體   English   中英

JavaScript在Windows Mobile和Windows Phone上不起作用

[英]JavaScript is not working on Windows Mobile and Windows Phone

我使用jQuery mobile編寫了一個混合應用程序。 它可以在Android和iPhone上運行,但是在Windows Phone上可以顯示UI,但是JavaScript功能無法正常工作。

這是我的代碼:

<html >
    <head>
           <script type="text/javascript">
            function  checkUser(){

                //here is my logic to to next screen
                         }
       </script>
   </head>
   <body>
     <div data-role="page" data-theme="b" id="page1">
          <p>
     <a data-role="button" data-transition="none" data-theme="e" onclick="checkUser(); "  rel="external"> Login </a>
          </p>
     </div>
   </body>
</html>

當我單擊登錄按鈕時,不會調用checkUser函數。 我究竟做錯了什么?

您應該在那里有一個href 例如: <a href="#" onclick="someFunction()">

您有很好的機會使用不引人注目的JS-自從使用jQuery以來,更多的機會了:

<html >
  <head>
    <script... jquery...></script>
       <script type="text/javascript">
          $(function() {
            $("#page1 a").on("click",function() {
              //here is my logic to to next screen
              return false; // or e.preventDefault()
            });
          });
   </script>
 </head>
 <body>
 <div data-role="page" data-theme="b" id="page1">
      <p>
 <a href="#" data-role="button" data-transition="none" data-theme="e" rel="external"> Login </a>
      </p>
 </div>
 </body>
 </html>

不幸的是,Windows Mobile 6以及可能的Windows Phone瀏覽器不支持完整的javascript標准。 例如,在Windows Mobile 6.1.4(AKU版本levlel)之前,沒有onKey ... javascript支持。 要查看是否存在WinodwsMobile Internet Explorer Mobile(IEM)不支持的功能,請啟用ShowScriptErrors:

// If you want Pocket IE to display script errors set this registry key:
// [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] "ShowScriptErrors"=dword:00000001
// MSDN Knowledge Base Q306520
// Recommended !!

另請參見http://forum.gpsgate.com/pop_printer_friendly.asp?TOPIC_ID=1499

我不知道,WM支持JQuery多遠,但是以下是一個可工作的代碼段,用於調用按鈕的javascript函數:

<input type="button" style="width:90" name="pushbutton_0" value=" F2-Zrks" onfocus="javascript:doOnFocus(0);" onclick="javascript:doSubmit(0);">

〜約瑟夫

我使用Windows Phone的VS Express 2012的html模板創建了一個新項目。

按照“ nkchandra”的建議,我需要在MainPage.xaml文件中啟用Javascript(請參閱IsScriptEnabled ):

<Grid x:Name="LayoutRoot" Background="Transparent">
    <phone:WebBrowser x:Name="Browser"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      Loaded="Browser_Loaded"
                      IsScriptEnabled = "True"
                      NavigationFailed="Browser_NavigationFailed" />
</Grid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM