- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试制作一个验证电话号码和姓名的表单,但无论何时输入提交,无论字段是否填写,它都只会输入相同的消息。消息不断出现,我想不通
预计到达时间:http://jsfiddle.net/6W3uU/
<body>
<form id="contact">
<fieldset id="contactInformation">
<legend>Contact Information</legend>
<p id="error"></p>
<label id="name">Name:</label>
<br>
<input type="text">
<br>
<br>
<label id="phoneNumber">Phone Number:</label>
<br>
<input type="text">
<br>
<br>
<label id="eMail">E-Mail Address:</label>
<br>
<input type="text">
<br>
<br>
<label id="address">Address:</label>
<br>
<input type="text">
<br>
<br>
<label id="city">City:</label>
<br>
<input type="text">
<br>
<br>
<label id="postalCode">Postal Code:</label>
<br>
<input type="text">
<br>
<br>
<label id="province">Province</label>
<br>
<select id="province">
<option id="choose">Choose Your Province</option>
<option id="alberta">Alberta</option>
<option id="britishColumbia">British Columbia</option>
<option id="manitoba">Manitoba</option>
<option id="newBrunswick">New Brunswick</option>
<option id="newfoundland">Newfoundland and Labrador</option>
<option id="northwestTerritories">Northwest Territories</option>
<option id="noviaScotia">Nova Scotia</option>
<option id="nunavut">Nunavut</option>
<option id="ontario">Ontario</option>
<option id="pei">Prince Edward Island</option>
<option id="quebec">Quebec</option>
<option id="saskatchewan">Saskatchewan</option>
<option id="yukon">Yukon Territory</option>
<br>
<br>
<br>
<label id="shippingCheckbox">Is your shipping information the same as your contact information?
<input type="radio" id="sameInfo">
<label>
Yes it is
</label>
<br>
<br>
<input type="radio" id="notSameInfo">
<label>
No it is not
</label>
<br>
<br>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
<br>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
这是脚本:
//script.js
var errorNotify = 'Sorry, we could not process your request because '
var errorField = [];
function formVal() {
var isValid = true;
for (var i = 0; i < errorField.length; i++ ) {
$(errorField[i]).removeClass('error');
}
errorField = [];
if(!nameCheck()) {
isValid = false;
}
if(!phoneCheck()) {
isValid = false;
}
if (isValid === false) {
$('#error').html(errorNotify).hide().slideDown('slow');
for (var i = 0; i < errorField.length; i++) {
$(errorField[i]).addClass('error');
}
errorNotify = 'Sorry, we could not process your request because ';
}
function nameCheck(){
if ($('#name').val() === '') {
errorNotify += ' you did not enter your name.';
errorField.push($('#name'));
return false;
} else {
return true;
}
}
function phoneCheck(){
var phoneCheck = $('#phoneNumber').val();
if (phoneCheck === '') {
errorNotify += ' you did not enter your phone number.';
errorField.push($('#phoneNumber'));
return false;
} else if (phoneCheck.length !== 10) {
errorNotify += 'please enter a 10 digit phone number';
errorField.push($('#phoneNumber'));
}
else if (isNaN(parseInt(phoneCheck))) {
errorNotify += 'you have entered a letter, please enter a number';
errorField.push($('#phoneNumber'));
}
else {
return true;
}
}
return isValid;
}
$(function () {
$('#contact').submit(function() {
return formVal();
});
});
最佳答案
你的 id 在 label 标签上,而不是输入字段,改变
<label id="name">Name:</label>
<br>
<input type="text">
到
<label for="name">Name:</label>
<br>
<input id="name" type="text">
等等
关于javascript - 表单验证不适用于电话号码/姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15533470/
我正在使用 ajax 实时搜索来选择名称和姓氏的串联与输入的文本匹配的所有用户,并且效果很好: $sql = "SELECT * FROM users WHERE concat(name,' ',su
我尝试建立一个注册表单。该注册表单为名为“address1”的文本框,其附近有一个名为“Add Address”的按钮。该按钮的功能 - 添加更多地址的文本框。先前地址框附近的按钮更改为“删除”,从而
我一直在尝试制作一个验证电话号码和姓名的表单,但无论何时输入提交,无论字段是否填写,它都只会输入相同的消息。消息不断出现,我想不通 预计到达时间:http://jsfiddle.net/6W3uU/
我正在寻找验证 上的姓名和电子邮件输入的代码 我希望用户名只有 A-Z , a-z并且必须有一个下划线 _ , 电子邮件应该有一个 @ .我怎样才能用 jQuery 做到这一点? 表格(示例):
我在db中有一个带有id,name和parent的部门表.parent是与父root对应的id。现在我已经显示了id(父id),但是我想显示与之对应的部门的名称我已经在Departmentcontro
我正在尝试显示平均分最高的 worker 的姓名。我的第一个表是 worker 表并存储 worker_id 和 worker_name。第二张表是测试表,存储了参加测试的worker_id、test
用什么方法或变量可以找到本例中父对象的名称?也就是说,当鼠标悬停在第一个按钮上时,获取名称 $GetParentName = "Button01",第二个 $GetParentName = "Butt
我有一个数据库,其中一个表中有父名称。列:id、名称。以及其他表中的id、parent_id、name。在搜索字段中我输入名称。更不用说鲍勃、爱丽丝和汤姆了。我必须在数据库中搜索 child 名为鲍勃
我有以下查询: SELECT ty.id, ty.type, ty.pid, if(ty.pid = 0, '-', (select ty.type from bid_type ty w
我有一个如下所示的数据库: CREATE TABLE Persons ( id int, parentID int, name varchar(255) ); INSERT I
我无法获得预期的结果我希望我的程序显示任何人都可以帮助我。该程序用于打印结构中列出的 worker 姓名,如果您不输入任何这些姓名,我应该打印不存在的 worker 姓名。有人可以告诉我要使用的代码/
我正在读取 JSON 对象并以表格格式名称和文本在 html 中显示它们,但无法使用 javascript 获取节点的父名称 { "A": { "B": "Text",
当用户在我的 iPad 报亭应用上购买杂志订阅时,他们会收到分享一些信息的提示: 分享您的信息? [此处的应用名称] 的发布者希望根据他们的隐私政策使用您的姓名、电子邮件和邮政编码。 但是,我似乎无法
我有一大堆电子邮件,需要从中提取信息。我最近接手了一个网站,该网站将客户的所有联系信息存储在电子邮件中。他们想要开始将其存储在数据库中。我正在使用 Java 来尝试提取这些信息。我有点陷入困境。 我能
我有一个使用 qbXml 和 Intuit Web 连接器与 QuickBooks 同步的应用程序。 我在查询帐户时注意到一些异常行为。根据规范,一个帐户的全名应该包括它的任何祖先的名字,用冒号分隔。
下面是一个更大的数据框的示例。 Fare Cabin Pclass Ticket Name 257 86.5000 B77 1 110152
我在我的 Program.cs 文件中有一个方法要实现。当该方法遍历作业列表(其中每个作业都是一个字典)时,它应该打印: ***** name: Data Scientist / Business I
如何从包含三列的表格中查找第二高薪水,这些列是id、name、 salary,但在SELF JOIN中使用。通过嵌套查询得到答案。但是,我想知道我们如何使用 SELF JOIN 构建框架 最佳答案 如
我想在 WooCommerce 中运行 SQL 查询来选择所有没有订单、姓名、实际地址和电话号码的用户。我已经运行了以下代码,但它对我不起作用。 SELECT * FROM wp_usermeta
给定(例如): Dog breeds (Name) | id Labrador Retriever | A1 German Shepherd | A2 Golden Retriever |
我是一名优秀的程序员,十分优秀!