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