最佳答案
检查有效的正则表达式和长度。您的正则表达式对于空字段已成功。
您可以在此处检查 jQuery 元素集合的长度
if(!$("#sForm input#write").length > 0) $("input#sub").hide();
但是你必须检查值的长度
detectEmail.length == 0
Updated jsFiddle
$('input#sub').hide();
$('input').keyup(function() {
$('span.attention').hide();
var detectEmail = $(this).val();
var emailRegex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(detectEmail.length == 0 || !emailRegex.test(detectEmail))
{
$('#sub').hide();
$(this).after('<span class="attention">Writing valid e-mail...</span>');
}
else
{
$('#sub').show();
}
});
关于jQuery - 当您删除输入字段中的电子邮件时如何动态隐藏提交按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9191266/