我有一个html代码:
<html>
<title> Upload Malware File </title>
<body>
<header id = "header">
<h1 align="center">Upload Malware File</h1>
<p align="center"> Please choose the malware file you want to upload.</p>
</header>
<form method="post" enctype="multipart/form-data" action="malware_upload.php">
Select malware file to upload:
<input type="file" name="file"required>
<form method="post" enctype="multipart/form-data">
<div >
<label for="mname"><b>Malware Name</b></label>
<input type="text" placeholder="Malware Name" name="mname" <required> *HERE*
</div>
<div >
<label for="uname"><b>Admin Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
</div>
<div>
<label for="psw"><b>Admin Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
</div>
<input type="submit" value="Upload" name="submit">
</form>
</form>
<form>
<input type="submit" formaction="file_upload.php" value="Go to File Uploads" />
<input type="submit" formaction="CreateAdmin.php" name="SI" value="Sign In" />
</form>
<form method="post" enctype="multipart/form-data">
<input type="submit" name = "logout" value="Logout" />
</form>现在我有了这样的方法:
function checkMalwareName(string)
{
return ("/^[a-zA-Z0-9]+$/").test(string)
}我如何能够在html代码中的“此处”标记处调用checkMalwareName,如果错误为false,则返回错误?
发布于 2018-05-07 23:53:31
必须将函数绑定到元素的事件(oninput):
变化
<input type="text" placeholder="Malware Name" name="mname" <required>至
<input type="text" placeholder="Malware Name" name="mname" oninput="checkMalwareName(this.value)" required >https://stackoverflow.com/questions/50223901
复制相似问题