Javascript验证无法使用正则表达式
我的javascript验证程序不工作。当我不输入任何内容时,不会显示警报。另外,你们能给我解释一下关于表单的动作方法是什么,以及我应该如何使用它吗Javascript验证无法使用正则表达式,javascript,regex,forms,Javascript,Regex,Forms,我的javascript验证程序不工作。当我不输入任何内容时,不会显示警报。另外,你们能给我解释一下关于表单的动作方法是什么,以及我应该如何使用它吗 <form method = "post" id = "my_form"> <h1> Thank you for visiting our website! Please take some time to fill out our service questions! </h1>
<form method = "post" id = "my_form">
<h1> Thank you for visiting our website! Please take some time to fill out our service questions! </h1>
<h2> The ratings given are F, D, C, B and A. </h3>
<h3> How would you rate the service that this webpage provides?? </h3>
<input type = "text" font-size = "15px" id = "name">
<h3> How would you rate the organization and usability of this webpage?? </h3>
<input type = "text" font-size = "15px" id = "name">
<h3> How would you rate the professionalism of this webpage?? </h3>
<input type = "text" font-size = "15px" id = "name">
<h3> How would you rate the overall look of this webpage??</h3>
<input type = "text" font-size = "15px" id = "name">
<br /><br />
<input type = "submit" id = "submit" value = "submit" name = "submit">
</form>
<script type = "text/javascript">
var my_form = document.getElementById("my_form");
my_form.addEventListener("submit", function(event) {
var name = document.getElementById("name").value;
var tomatch = /[a-f]/i;
if (!tomatch.test(name)) {
event.preventDefault();
window.alert("The name can only contain letters from a-f");
}
}. false);
</script>
感谢您访问我们的网站!请花些时间填写我们的服务问题!
给出的评级为F、D、C、B和A。
您如何评价此网页提供的服务??
您如何评价此网页的组织和可用性??
你如何评价这个网页的专业性??
你如何评价这个网页的整体外观??
var my_form=document.getElementById(“my_form”);
my_form.addEventListener(“提交”),函数(事件){
var name=document.getElementById(“name”).value;
变量tomatch=/[a-f]/i;
如果(!tomatch.test(名称)){
event.preventDefault();
window.alert(“名称只能包含来自a-f的字母”);
}
}(虚假),;
您有多个相同ID的输入,此处的语法错误
my_form.addEventListener("submit", function(event) {
// bunch of code...
}. false); // <-- not dot, but comma
您有多个相同ID的输入,此处的语法错误
my_form.addEventListener("submit", function(event) {
// bunch of code...
}. false); // <-- not dot, but comma
用于正则表达式
var tomatch = new RegExp("/[a-f]/i");
关于正则表达式的用法。
var tomatch = new RegExp("/[a-f]/i");
注意。
id
在HTML中应该是唯一的。您可能需要避免使用id=“name”
4次。id
在HTML中应该是唯一的。您可能需要避免使用id=“name”
4次。如果我想添加一个将信息发送到php文档的操作,会发生什么?如果用户提交了正确的信息,请阅读html表单元素上的文档,您只需添加属性为的操作和方法form@FranckRaul更新,添加的操作和方法属性如果我想添加一个将信息发送到php文档的操作会发生什么如果用户提交了正确的信息读取html表单元素上的文档,您只需要添加属性为的操作和方法form@FranckRaul更新、添加了操作和方法属性