【发布时间】:2014-07-10 18:13:26
【问题描述】:
我正在使用 Jquery 代码在发送表单之前检查电子邮件输入字段是否为空。
这是我的电子邮件输入 html:
<input class="sml_emailinput" type="email" value="" placeholder="votre adresse e-mail" name="sml_email"></input>
这是我的提交按钮:
<input class="btn sml_submitbtn" type="submit" value="OK" name="submit"></input>
这段代码可以正常工作:
function submit_newsletter(){
var $submit = $("input[type=submit]"),
$inputs = $("input[type=email]");
function checkEmpty() {
return $inputs.filter(function() {
return !$.trim(this.value);
}).length === 0;
}
$inputs.on('blur', function() {
$submit.prop("disabled", !checkEmpty());
}).blur();
}
问题是我在我的网站上使用了其他输入字段,因此我需要仅使用输入类型和输入名称来定位这两个特定字段。
我尝试了很多方法,但我真的不明白为什么它不起作用。
这里是我试过的代码:
function submit_newsletter(){
var $submit = $("input[type='submit', name='submit']"),
$inputs = $("input[type='email', name='sml_email']");
function checkEmpty() {
return $inputs.filter(function() {
return !$.trim(this.value);
}).length === 0;
}
$inputs.on('blur', function() {
$submit.prop("disabled", !checkEmpty());
}).blur();
}
谁能帮我解决这个问题? 我无法更改两个输入的 html,因为它是由插件生成的。
非常感谢
【问题讨论】:
标签: javascript jquery html forms input