1

当我直接从 JavaScript 作为 window.open("reg.htm") 调用 reg.htm 时,我的 index.html 代码工作正常(页面上的 JavaScript 被调用,AJAX 和回调都正常工作,我的数据库也被更新)。但是,当使用标记调用 REG.HTM 并放置 data-rel="dialog" 的 jQueryMobile 标记时,文件会打开,但不会调用任何 JavaScript。

index.html(作品)电影提醒

    <style type="text/css">
    <!--
    .image    { position: relative; width: 100%; /* for IE 6 */ }
    .register { position: absolute; top: 250px; left: 0; width: 100%; padding-left: 106px;}
    .login    { position: absolute; top: 250px; left: 0; width: 100%; padding-left: 106px;}
    -->
    </style>

    <script language="Javascript">
        document.addEventListener("deviceready", onDeviceReady, false);         
        // Cordova is ready
        function onDeviceReady() 
            {
            var user = window.localStorage.getItem("user");
            alert ("Device Ready");
            if  (user == null) 
                window.open("reg.htm");
            else
                {
                var token = window.localStorage.getItem("token");
                if  (token == null) 
                    window.open("login.htm");
                else 
                    window.open("search.htm");                
                }
            }

        $(document).ready(function() {
            setTimeout("onDeviceReady()", 2000);
        });     
    </script>

</head>
<body topmargin="0" leftmargin="0">
<div class="image">
    <img src="images/mov-rem-bkgd.jpg" alt=""  />
</div>        
</body>
</html>

这是使用不起作用的标签调用的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Movie Reminder</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>

    <style type="text/css">
    <!--
    .image    { position: relative; width: 100%; /* for IE 6 */ }
    .register { position: absolute; top: 250px; left: 0; width: 100%; padding-left: 106px;}
    .login    { position: absolute; top: 250px; left: 0; width: 100%; padding-left: 106px;}
    -->
    </style>

    <script language="Javascript">
        document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady() {
            if  (window.localStorage.getItem("user") == null) 
                $('.register').show();
            else {
                if  (window.localStorage.getItem("token") == null) $('.login').show();
                else window.open("search.htm");                
                }
            }
        $(document).ready(function() { setTimeout("onDeviceReady()", 2000); });
    </script>

</head>
<body topmargin="0" leftmargin="0">
<div class="image">
    <img src="images/mov-rem-bkgd.jpg" alt=""  />
    <div class="register">
        <a href="reg.htm" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Register</a>
    </div>
    <div class="login" style="display:none">
        <a href="login.htm" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Login</a>
    </div>
</div>        
</body>
</html>

如果您创建一个简单的 reg.htm 文件,其中包含以下代码,您将看到 JavaScript 不是由 index2.htm 仅由 index1.htm 调用的。

<script>
    $(document).ready(function() {
        alert ("doc ready");
        $('.ui-btn-hidden').click(function(event) {
            $("#regform").submit(function(event) {   
                if  ($('.ui-btn-hidden').attr("value") == "Submit") 
                    {
                    alert ("inside submit");
                    var postData = "username=foo";
                    var urlStr = "http://www.fohost.co/mr/regUser/index.php?"; 
                    $.ajax({
                        url: urlStr,
                        data: encodeURI(postData),
                        dataType: "jsonp",
                        success: doCallback
                        });
                    return false;
                    }
            });
        }); 
    });

    function doCallback(data) {
        alert("doCallback");
        if  (data.success == "true")
            window.open("login.htm");
        }
</script>

有人有什么想法吗?

4

1 回答 1

-1

阅读脚本页面。也适用于对话框。

于 2012-06-18T06:07:17.957 回答