如果 JavaScript 被禁用,您的客户端验证都不会正常工作。此外,您禁用按钮的代码也将不起作用,因为它是 javascript :(
如果 JavaScript 被禁用,您可以尝试这样的方法来隐藏您的表单并向用户显示消息。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.hidden {
display:none;
}
</style>
</head>
<body>
<noscript>JavaScript is disabled. </noscript>
<form method="POST" action="http://www.google.com" id="my-form" class="hidden">
<input type="text" value="Some text here" />
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
document.getElementById("my-form").style.display = "block";
</script>
</body>
</html>
或者您可以执行任何这些方法将用户重定向到另一个页面。
<noscript>
<meta http-equiv="refresh" content="0;url=your-noscript-page.html">
</noscript>
或这个
<noscript>
<a href="your-noscript-page.html">JavaScript is disabled in your browser. Click here to continue</a>
</noscript>
或不使用 Modernizr 库的 Modernizr 方法。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.no-js form {
display:none;
}
.js-disabled {
display:none;
}
.no-js .js-disabled {
display:block;
}
</style>
</head>
<body class="no-js">
<div class="js-disabled">JavaScript is disabled in your browser.</div>
<form method="POST" action="http://www.google.com" id="my-form">
<input type="text" value="Some text here" />
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
document.getElementsByTagName("body")[0].className = "";
</script>
</body>
</html>