我有以下代码,我尝试定义输入的值是否等于电子邮件来执行某些操作。但它永远不会认出正确的价值。
有什么想法吗?
https://jsfiddle.net/koo29obw/
$('.signInButton').on('click', function(){
if($('input[name=email]').val() == 'email@gmail.com'){
console.log('holla');
}else{
console.log('nope');
}
});
答案 0 :(得分:1)
名称不正确。它应该是email_username
。所以改变这个:
$('input[name=email')
到此:
$('input[name=email_username]')
$('.signInButton').on('click', function() {
if ($('input[name=email_username]').val() == 'email@gmail.com') {
console.log('holla');
} else {
console.log('nope');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="signInInput" name="email_username" placeholder="Email or Username" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}"/>
<div class="signInButton">Sign In</div>