验证通过后,使提交可点击 [英] Make a submit clickable after validations are met

查看:64
本文介绍了验证通过后,使提交可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下html:

<p>Genre: {{ create_production_form.genre }}</p>
<p>Privacy: {{ create_production_form.privacy }}</p>
<p><input type="submit" name="next" value="Next" disabled="disabled"></p>

仅在填写体裁"和隐私"后,我如何才能使next按钮可点击?例如,类似:

How would I make the next button clickable only after Genre and Privacy are filled in? For example, something like:

if ($("id_genre").val() && $("id_privacy").val()) {
    $("input[name=next]").attr("disabled","")
}

唯一的是,它必须是实时的",以便它可以检测何时填写所有这些字段.

The only thing is, it'd need to be 'live', so it can detect when all these fields are filled in.

推荐答案

会吗? 事件"处理委托,因此事件处理程序"需要具有live()on(),具体取决于您所使用的jQuery版本.这意味着方程式的重要部分已被遗漏.

Wut? The 'event' handles the delegation, so the 'event handler' needs to have live() or on() depending on the version of jQuery you're using. This means that an essential piece of the equation has been left out.

我所说的事件"方法是submitchangeclick.您必须使用上述live()on()方法将代码委派给这些事件之一.

The 'event' methods I'm speaking of are submit, change or click. You must delegate the code to one of these events -- using the aforementioned live() or on() methods.

否则,如果您只是想在数据已填满时启用它们.

Otherwise, if you're just simply looking to enable them if data has been fille din.

$('form :input').change(function(){
  if ($("id_genre").val() && $("id_privacy").val()) {
    $("input[name=next]").attr("disabled","")
  }
});

这将检查表单以查看输入是否更改,如果输入更改,它将测试值,您将得到结果.

This wil check the form to see if the inputs change, if they do, it will test the values and you'll get your result.

这篇关于验证通过后,使提交可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆