簡體   English   中英

點擊按鈕后頁面重新加載

[英]Page reloads even after button click

我有3個html文件 - start.html,loginPage.html和dashboard.html。 單擊登錄按鈕時,它應該加載儀表板,但我無法訪問該按鈕。

的start.html

<html>
<head>
    <meta http-equiv="Content-Security-Policy">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <title>Amazon App</title>
</head>

<body onload="init()">
    <br><br>

    <div id='content'>
        <center><img src='img/splashlogo.png'/><center>
    </div>

    <script src="cordova.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.mobile.min.js"></script>
    <script src="require.js"></script>
    <script src="aws-sdk-2.1.34.min.js"></script>
    <script src="js/check.js"></script>
  </body>
 </html>

loginPage.html

<link rel="stylesheet" href="css/index.css"/>
<SCRIPT TYPE="text/javascript">
function setValues(){
    $("#accessKey").val('MY-ACCESS-KEY');
    $("#secretKey").val('MY-SECRET-KEY');
}
</SCRIPT>

 <div data-role="page" id="start" data-enhance="false" style = 'background: url(../img/BG.png);'>
<div data-role = "content">
    <br><br>
    <div align="right">
        <img src="./img/help-icon.png" onClick= "setValues()"/>
    </div>
   <div align = "center">
   <img src="./img/Logo login screen.png" height="200" width="170"/>
    </div>

    <br><br>
    <form id="loginForm" align = "center" data-ajax="false">
        <div id="user" align = "center">
            <input class="amazeFont" type="text" id = "accessKey" Placeholder="Access Key (20 characters)" size="30" maxlength="128" tabindex="1" autocomplete="on" autocorrect="off" autocapitalize="off" data-validation="[NOTEMPTY]"/>
        </div>
        <br><br>
        <div id = "pass" align = "center">
            <input class="amazeFont" type="password" id = "secretKey" Placeholder = "Secret Key (40 characters)" size="30" maxlength="1024" autocomplete="on" tabindex="2" data-validation="[NOTEMPTY]"/>
        </div>
        <br><br>
        <center><button type = "submit" id="submitButton" style='width: 80%; height: 40px; background-color: #f15a29; font-weight: bold; color: white; cursor: pointer;'>Login</button></center>
    </form>
   </div>
 </div>

 <script src="cordova.js"></script>
 <script src="js/jquery.min.js"></script>
 <script src="js/jquery.mobile.min.js"></script>
 <script src="require.js"></script>
 <script src="aws-sdk-2.1.34.min.js"></script>
 <script src="js/fun.js"></script>
 <script src="js/check.js"></script>

JS:

function init(){
   document.addEventListener("deviceReady", onDeviceReady,false);
}

function onDeviceReady(){
     window.location = 'loginPage.html';
     document.getElementById('submitButton').addEventListener("click", startApp,false); 

}

function startApp(){
    alert('switching page');
    window.location= 'dashboard.html';
}

登錄頁面不會切換到儀表板頁面。它會重新加載。 沒有捕獲按鈕單擊。 我想讓頁面滑動。

編輯:

更新的js:

function init(){
   document.addEventListener("deviceReady", onDeviceReady,false);
 }

 function onDeviceReady(){
     window.location = 'loginPage.html';
 }

為loginPage.html創建了第二個js並將其添加到loginPage.html的主體

function init(){
    document.addEventListener('deviceReady', onDeviceReady, false);
 } 

function onDeviceReady(){
   document.getElementById('submitButton').addEventListener("click", startApp,false);
}

function startApp(){
//alert('switching page');
   window.location= 'dashboard.html';
}

未調用dashboard.html

您正在從start.html調用init()方法,其中onload調用function onDeviceReady()具有位置更改,因此其他頁面加載。 您需要添加document.getElementById('submitButton').addEventListener("click", startApp,false); 當login.html.html(可能在不同的函數中)頁面加載時,不是在start.html加載時。

希望能幫助到你。

暫無
暫無

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

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