簡體   English   中英

JavaScript登錄按鈕在IE中有效,但在Chrome或Firefox中不起作用

[英]JavaScript login button works in IE but not in Chrome or Firefox

我有一個非常簡單的網頁,要求用戶輸入登錄名和密碼並按登錄按鈕。 這在IE中可以很好地工作,但在Chrome或Firefox中則不能,有人可以告訴我原因或正確的方向嗎?

<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet type="application/xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">

<html>

<head>


<title>Test Online Login</title>

<script>

<xsl:if test="VFILE_DATA/LOGGED_IN='TRUE'">

  // Logged in OK so run menu

 document.URL = "http://gla-web01:91/scripts/test.wsc/vfxmlsws.p?" +
                "function=system_blank" +
                "&amp;xsl=Personal.xsl" +
                "&amp;session_key=<xsl:value-of select="VFILE_DATA/SESSION_KEY"/>";

</xsl:if>


function login(){

  // Check to see if login parameters are correct

  document.URL="http://gla-web01:91/scripts/test.wsc/vfxmlsws.p?"+"function=user_login"+"&amp;server_translate=false"+"&amp;xsl_dir=/vfile_test"+"&amp;user_id="+user.value+"&amp;password="+password.value+"&amp;xsl=install_login.xsl";

}

function checkReturnKey(){
    // Test to see if the return key has been pressed
    if ( event.keyCode == 13 )
      login();
  }

</script>
                    <style>
                table {
                    border-collapse: collapse;
                    width: 100%;
                    font-family:calibri
                }

                th, td {
                    text-align: left;
                    padding: 8px;
                    font-family:calibri
                }

                tr:nth-child(even){background-color: #E4E4E4}

                th {
                    background-color: #eedaff;
                    color: black;
                    text-align: left;
                    font: 16px/24px Helvetica Neue, "Arial", Helvetica, Verdana, sans-serif;
                    width: 100%;
                }

                label {    
                    color: #666;
                    text-align: left;
                    font: 16px/24px Helvetica Neue, "Arial", Helvetica, Verdana, sans-serif;
                    width: 100%;

                }
                </style>
</head>


<body>

<div id="title"><h2>Test User Login</h2>
<hr></hr></div>



  User:<input id="user" type="text" onkeypress="checkReturnKey()"/>

  Password:<input id="password" type="password" onkeypress="checkReturnKey()"/>


  <input class="loginButton" type="button" value="Login" onclick="login()"/>  
    <button onclick="login()">Login2</button>
<xsl:if test="VFILE_DATA/LOGGED_IN='FALSE'">
<P/>
Invalid Login

</xsl:if>


</body>

</html>

</xsl:template>
</xsl:stylesheet>

如您所見,我嘗試了兩種不同的登錄按鈕編碼方法,兩種方法都可以在IE中使用,但不能在Chrome或FireFox中使用。

我已經閱讀了幾個類似的主題:

為什么此按鈕在IE中有效但在Firefox中不起作用?

XSLT適用於IE,不適用於Chrome或Firefox

為什么此按鈕在IE中有效但在Firefox中不起作用?

Javascript可在IE中使用,但不能在Chrome中使用

javascript在IE中起作用,但在Firefox中不起作用

但沒有任何幫助。 我敢肯定這一定是真的很簡單,我想念但無法弄清楚!

謝謝,

(這可能是重復。)

keyCode是Microsoft特定的。 這是which在其他瀏覽器。 所以:

function checkReturnKey(){
    // Test to see if the return key has been pressed
    if ( (event.keyCode || event.which) == 13 ) {
        login();
    }
}

由於JavaScript的強大功能|| 運算符 ,它沒有布爾結果; 相反,如果該操作數為true ,則結果為第一個操作數,否則為第二個操作數。 因此,如果event.keyCode是真實值( undefined是虛假的),我們將13與該值進行比較; 如果是假的(例如undefined ),我們將event.which13進行比較。

我相信你也想上進行這樣keydown ,沒有keypress ; 例如:

<input id="user" type="text" onkeydown="checkReturnKey()"/>
<!-- -----------------------------^^^^                  -->

好的,事實很簡單,應該使用location.href而不是document.url使其在chrome中工作。

暫無
暫無

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

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