任何人都可以帮我在我的HTML中正确实现JavaScript,因此无法在我的登录名和密码表单中编写,'*+?
吗?
我的代码如下所示:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<script>
var Username =/[A-Za-z]/g;
var Password = /[A-Za-z]/g;
function restrictCharacters(myfield, e, restrictionType) {
if (!e) var e = window.event
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
if (code==27) { this.blur(); return false; }
if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
if (character.match(restrictionType)) {
return true;
} else {
return false;
}
}
}
</script>
<body>
<form>
<input type="text" name="Username" id="Username">
<input type="Password" name=Password" id="Password" method="POST">
<input type="Submit" name="Login" id="Login">
</form>
</body>
</html>
如果你能提供帮助,那就太棒了!
答案 0 :(得分:0)
以下是如何执行此操作的简单示例
<input type="text" onkeypress="return filter(event)"/>
<script>
function filter(evt)
{
var charCode = evt.which || evt.keyCode;
if ( charCode ==43 || charCode ==44 || charCode ==39 || charCode ==63 || charCode ==42 ) return false;
}
</script>
但您应该验证服务器端的所有输入。