在电话和电子邮件输入框中显示正确的fa fa图标 [英] Display correct fa fa icons inside phone and email input boxes
问题描述
在我的表单里面,电子邮件
我希望它显示上面的输入框(名和姓)的绿色复选标记圆圈图标。
此外,当数字无效时,手机
输入框会显示一个红色圆圈复选标记图标,我希望它显示一个红色圆圈x图标。
如果有人知道如何达到这个目标,那么您可以获得帮助!
不正确的fa fa图标显示在电子邮件和电话号码:
< img src =https://i.stack.imgur.com/ZcG0a.pngalt =在这里输入图片描述>
HTML:
< form class =containeraction =https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF- 8method =POST>
< label>名字
< input id =first_namemaxlength =40name =first_namesize =20type =textonkeyup =test()required> ;< i class =fa fa-check-circlearia-hidden =true>< / i>
< / label>
< label> Last Name
< input id =last_namemaxlength =80name =last_namesize =20type =textonkeyup =test()> ;< i class =fa fa-check-circlearia-hidden =true>< / i>
< / label>
< label>电子邮件
< span class =error>请输入一个有效的电子邮件地址< / span>
< input id =emailmaxlength =80name =emailsize =20type =textonkeyup =test()>< i class =fa fa- times-circle-oaria-hidden =true>< / i>
< / label>
< label>电话
< span class =error>请输入有效的电话号码< / span>
< input id =phonemaxlength =80name =phonesize =20type =telonkeyup =test()>< i class =fa fa- check-circlearia-hidden =true>< / i>
< / label>
< label> City
< input id =cityname =citymaxlength =40size =20type =textonkeyup =test()> < i class =fa fa-check-circlearia-hidden =true>< / i>
< / label>
< label>州/省
< input id =statemaxlength =20name =statesize =20type =textonkeyup =test() >< i class =fa fa-check-circlearia-hidden =true>< / i>
< / label>
< label id =co>公司
< input id =companyname =companytype =textonkeyup =test()>< i class =fa fa-check-circlearia-hidden =true>< / i>
< / label>
< label>评论
< textarea id =commentsname =id =cols =30rows =10onkeyup =test()>< / textarea的>
< input id =subtype =submitdisabled =disabled/>
< / label>
< div>
< option value => - 无 - < / option>
< option selected =selectedvalue =Visiant> Visiant< / option>
< option value =Tessellate> Tessellate< / option>
< / select>< br>
< select hidden =trueid =lead_sourcename =lead_source>
< option value => - 无 - < / option>
< option value =内部>内部< /选项>
< option value =贸易展>贸易展< / option>
< option selected =selectedvalue =Website> Website< / option>
< option value =直销> Direct Marketing< / option>
< option value =社交媒体>社交媒体< / option>
< option value =其他>其他< / option>
< / select>< br>
< / div>
< / form>
CSS:
body {
color:#fff;
background-color:#f78e2a;
text-align:center;
}
表格{
颜色:#fff;
background-color:#f78e2a;
text-align:center;
font-family:Lato;
}
* {
box-sizing:border-box;
}
.form-title {
font-size:38px;
颜色:#fff;
font-family:Lato;
letter-spacing:70px;
}
input [type =tel] {
width:100%;
身高:85%;
padding:10px;
背景颜色:#f9a558;
border:1px solid #fff;
}
input [type =text] {
width:100%;
padding:10px;
背景颜色:#f9a558;
border:1px solid #fff;
}
input [type =text]:focus {
background-color:#fff;
}
input [type =text]:visited {
background-color:#fff;
}
input [type =tel]:focus {
background-color:#fff;
}
input [type =tel]:visited {
background-color:#fff;
}
.container {
display:flex;
flex-direction:column;
padding:5px 0;
保证金余额:10%;
保证金:10%;
}
textarea {
width:100%;
背景颜色:#f9a558;
border:1px solid #fff;
}
textarea:focus {
background-color:#fff;
}
#co {
flex-basis:100%;
最大宽度:100%;
}
标签:nth-last-child(-n + 2){
flex-basis:100%;
最大宽度:100%;
}
select,
label {
height:50px;
宽度:48%;
保证金:2%1%;
text-align:left;
font-family:Lato;
}
#sub {
border-radius:6px;
width:120px;
height:35px;
text-transform:大写;
display:block;
margin-top:10px;
}
按钮{
margin-top:10px;
背景颜色:#B9B9B9;
颜色:#959595;
border-radius:6px;
width:120px;
height:35px;
保证金余额:1%;
display:block;
}
button:focus {
background-color:#fff;
颜色:#f78e2a;
}
@media(max-width:426px){
label {
width:98%;
}
}
@media(min-width:426px){
.container {
flex-direction:row;
flex-wrap:wrap;
align-self:flex-start;
}
}
标签{
position:relative;
}
.fa {
position:absolute;
bottom:0;
right:0;
transform:translate(-50%,-5%);
opacity:0;
转换:不透明度.5s,颜色.5s;
}
[data-valid] .fa {
opacity:1;
颜色:绿色;
}
[data-valid =valid] .fa {
color:green;
}
[data-valid =error] .fa {
color:red;
}
.error {
display:none;
颜色:红色;
font-size:.7em;
位置:绝对;
left:10px;
top:0;
transform:translateY(150%);
}
[data-valid =error] .error {
display:block;
}
jQuery:
function phoneNumber(phone){
var phoneno = / ^ \d {9} | \d {10} | \d { 11} $ /;
返回phoneno.test(电话); ('keyup',function(){
var $ label = $(this)。
$('input [type =tel]')。如果($(this).val()。trim()!=''){
if($(this).is('phone')),则最接近('label');
if {
if(phoneNumber($(this).val())){
$ label.attr('data-valid','valid');
} else {
$ label.attr('data-valid','error');
console.log(this works)
}
} else {
$ label.attr ('data-valid','valid');
console.log(this works)
}
} else {
$ label.removeAttr('data-valid ');
console.log(this works)
}
});
函数validateEmail(email){
var re = /^(([^<>()[\]\\.,;:\\ \\s @ \ ] +(。\ [^<>()[\] \\;:\s @ \。] +)*)|(\。 + \))@((\ [[0-9] {1,3} \。[0-9] {1,3} \。[0-9] {1,3} \ 。[0-9] {1,3} \])|(([A-ZA-Z\-0-9] + \)+ [A-ZA-Z] {2,})) $ /;
return re.test(email); ('keyup',function(){
var $ label = $(this)。
$('input [type =text]')。 ('label');
if($(this).val()。trim()!=''){
if($(this).is('#email')) {
if(validateEmail($(this).val())){
$ label.attr('data-valid','valid');
} else {
$ label.attr('data-valid','error');
console.log(this works)
}
} else {
$ label.attr ('data-valid','valid');
console.log(this works)
}
} else {
$ label.removeAttr('data-valid ');
console.log(this works)
}
}); $($#
$ b $ if $(#first_name).val()&& $(#last_name).val() && $(#email).val()&& $(#phone).val()&& $(#city).val()&& $ (#state)。val()&& $(#company)。val()){
$(#sub)。removeAttr(disabled);
$ / code $ / pre
解决方案脚本正在工作...
但是您根据验证结果不更改FA图标。
如果有效,请添加:
$(this).next(i)。removeClass(fa-times-circle-o)。addClass(fa -check圈);
如果有错误,请添加:
$(this).next(i)。removeClass(fa-check-circle)。addClass(fa-times-circle-o);
Inside my form the email
input box displays a green circle x when the email inside is correct.
I would like it to display a green check mark circle icon like the input boxes above (first name & last name).
In addition, the phone
input box displays a red circle check mark icon when the number is invalid and I would like it to display a red circle x icon instead.
If anyone knows how to achieve this your help is appreciated!
Incorrect fa fa icon displaying on email and phone number:
HTML:
<form class="container" action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<label>First Name
<input id="first_name" maxlength="40" name="first_name" size="20" type="text" onkeyup="test()" required><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>Last Name
<input id="last_name" maxlength="80" name="last_name" size="20" type="text" onkeyup="test()"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>Email
<span class="error">Please enter a valid email address</span>
<input id="email" maxlength="80" name="email" size="20" type="text" onkeyup="test()"><i class="fa fa-times-circle-o" aria-hidden="true"></i>
</label>
<label>Phone
<span class="error">Please enter a valid phone number</span>
<input id="phone" maxlength="80" name="phone" size="20" type="tel" onkeyup="test()"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>City
<input id="city" name="city" maxlength="40" size="20" type="text" onkeyup="test()"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>State/Province
<input id="state" maxlength="20" name="state" size="20" type="text" onkeyup="test()"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label id="co">Company
<input id="company" name="company" type="text" onkeyup="test()"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>Comments
<textarea id="comments" name="" id="" cols="30" rows="10" onkeyup="test()"></textarea>
<input id="sub" type="submit" disabled="disabled" />
</label>
<div>
<select hidden="true" id="00N6A000008yXMN" name="00N6A000008yXMN" title="Product Interest">
<option value="">--None--</option>
<option selected="selected" value="Visiant">Visiant</option>
<option value="Tessellate">Tessellate</option>
</select><br>
<select hidden="true" id="lead_source" name="lead_source">
<option value="">--None--</option>
<option value="Internal">Internal</option>
<option value="Trade Show">Trade Show</option>
<option selected="selected" value="Website">Website</option>
<option value="Direct Marketing">Direct Marketing</option>
<option value="Social Media">Social Media</option>
<option value="Other">Other</option>
</select><br>
</div>
</form>
CSS:
body {
color: #fff;
background-color: #f78e2a;
text-align: center;
}
form {
color: #fff;
background-color: #f78e2a;
text-align: center;
font-family: Lato;
}
* {
box-sizing: border-box;
}
.form-title {
font-size: 38px;
color: #fff;
font-family: "Lato";
letter-spacing: 70px;
}
input[type="tel"] {
width: 100%;
height: 85%;
padding: 10px;
background-color: #f9a558;
border: 1px solid #fff;
}
input[type="text"] {
width: 100%;
padding: 10px;
background-color: #f9a558;
border: 1px solid #fff;
}
input[type="text"]:focus {
background-color: #fff;
}
input[type="text"]:visited {
background-color: #fff;
}
input[type="tel"]:focus {
background-color: #fff;
}
input[type="tel"]:visited {
background-color: #fff;
}
.container {
display: flex;
flex-direction: column;
padding: 5px 0;
margin-left: 10%;
margin-right: 10%;
}
textarea {
width: 100%;
background-color: #f9a558;
border: 1px solid #fff;
}
textarea:focus {
background-color: #fff;
}
#co {
flex-basis: 100%;
max-width: 100%;
}
label:nth-last-child(-n+2) {
flex-basis: 100%;
max-width: 100%;
}
select,
label {
height: 50px;
width: 48%;
margin: 2% 1%;
text-align: left;
font-family: "Lato";
}
#sub {
border-radius: 6px;
width: 120px;
height: 35px;
text-transform: uppercase;
display: block;
margin-top: 10px;
}
button {
margin-top: 10px;
background-color: #B9B9B9;
color: #959595;
border-radius: 6px;
width: 120px;
height: 35px;
margin-left: 1%;
display: block;
}
button:focus {
background-color: #fff;
color: #f78e2a;
}
@media (max-width: 426px) {
label {
width: 98%;
}
}
@media (min-width: 426px) {
.container {
flex-direction: row;
flex-wrap: wrap;
align-self: flex-start;
}
}
label {
position: relative;
}
.fa {
position: absolute;
bottom: 0;
right: 0;
transform: translate(-50%, -5%);
opacity: 0;
transition: opacity .5s, color .5s;
}
[data-valid] .fa {
opacity: 1;
color: green;
}
[data-valid="valid"] .fa {
color: green;
}
[data-valid="error"] .fa {
color: red;
}
.error {
display: none;
color: red;
font-size: .7em;
position: absolute;
left: 10px;
top: 0;
transform: translateY(150%);
}
[data-valid="error"] .error {
display: block;
}
jQuery:
function phoneNumber(phone) {
var phoneno = /^\d{9}|\d{10}|\d{11}$/;
return phoneno.test(phone);
}
$('input[type="tel"]').on('keyup', function() {
var $label = $(this).closest('label');
if ($(this).val().trim() != '') {
if ($(this).is('#phone')) {
if (phoneNumber($(this).val())) {
$label.attr('data-valid', 'valid');
} else {
$label.attr('data-valid', 'error');
console.log("this works")
}
} else {
$label.attr('data-valid', 'valid');
console.log("this works")
}
} else {
$label.removeAttr('data-valid');
console.log("this works")
}
});
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
$('input[type="text"]').on('keyup', function() {
var $label = $(this).closest('label');
if ($(this).val().trim() != '') {
if ($(this).is('#email')) {
if (validateEmail($(this).val())) {
$label.attr('data-valid', 'valid');
} else {
$label.attr('data-valid', 'error');
console.log("this works")
}
} else {
$label.attr('data-valid', 'valid');
console.log("this works")
}
} else {
$label.removeAttr('data-valid');
console.log("this works")
}
});
test = function() {
if ($("#first_name").val() && $("#last_name").val() && $("#email").val() && $("#phone").val() && $("#city").val() && $("#state").val() && $("#company").val()) {
$("#sub").removeAttr("disabled");
}
}
解决方案 Your script is working...
But you just dont change the FA icon depending on the validation result.
If valid, add:
$(this).next("i").removeClass("fa-times-circle-o").addClass("fa-check-circle");
If error, add:
$(this).next("i").removeClass("fa-check-circle").addClass("fa-times-circle-o");
这篇关于在电话和电子邮件输入框中显示正确的fa fa图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!