首先,我對(duì)此很陌生,我真的盡力了解它是如何工作的。我有以下簡(jiǎn)單的登錄表單,如果提交正確的登錄憑據(jù),該表單將進(jìn)入主頁(yè)。然而,當(dāng)在禁用 JavaScript 的 Firefox 中運(yùn)行時(shí),登錄憑據(jù)將被忽略,并且無(wú)論我提供什么登錄詳細(xì)信息,我的主頁(yè)都會(huì)顯示。我創(chuàng)建了一條消息,<noscript></noscript>當(dāng) JavaScript 被禁用時(shí)會(huì)在該消息之間觸發(fā)。我想要實(shí)現(xiàn)的是,僅顯示警告消息,并且表單等被禁用,并且在啟用 JavaScript 的情況下重新加載登錄頁(yè)面之前不會(huì)顯示。有人可以幫我解決這個(gè)問(wèn)題嗎?非常感謝!我的代碼是<!doctype html><!-- This is is the main start page saved in index.html --><html><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><body><h2>Login details</h2><noscript> <h3>Before you login</h3> <p>JavaScript needs to run for this site to work properly.<br /> Please activate JavaScript in your browser<br /> and reload this page to login. </p></noscript><form id="myForm" name="login" onsubmit="return validateFormOnSubmit()" action="http://localhost:8080/index.html" method="post"><fieldset> <label for="username">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="password">Password:</label><br> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Submit"> </fieldset></form></body></html><script> function validateFormOnSubmit() { var un = document.login.username.value; var pw = document.login.password.value; var username = "username" var password = "password" if ((un == username) && (pw == password)) { return true; } else { alert ("Login was unsuccessful, please check your username and password"); return false; }}</script>
1 回答

慕尼黑5688855
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
您無(wú)需添加額外的 JavaScript 即可實(shí)現(xiàn)此目的。<noscript>您也可以在 中使用標(biāo)簽<head>,這樣您就可以使用 CSS 隱藏它:
…
<head>
…
<noscript>
<style>
#myForm {
display: none
}
</style>
</noscript>
</head>
…
- 1 回答
- 0 關(guān)注
- 110 瀏覽
添加回答
舉報(bào)
0/150
提交
取消