灰色了提交按钮,直到表格填写 [英] grey out submit button until form filled out

查看:186
本文介绍了灰色了提交按钮,直到表格填写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下形式:

 <form action="http://www.tahara.es/contact/subscribe.php" method="post" id="subscribe" name="subscribe">
      <input type="hidden" name="action" value="subscribe">
      <label>NAME:</label>
      <input type="text" name="name" class="Textbox" id="sub_first_name">
      <label>EMAIL:</label>
      <input type="text" name="email" class="Textbox" id="sub_email">
      <input type="submit" name="button" id="button" value="Subscribe" />

我想灰色,提交按钮,直到形式这两个领域已经填写。我猜的jQuery会做的伎俩?

I would like to grey out the submit button until both fields in the form have been filled out. I guess jquery would do the trick?

我怎样才能做到这一点,我应该在哪里放置脚本?

How can I do this, and where should I place the script?

推荐答案

jQuery的会那样做。在.keyup事件有jQuery的检查,如果这两个字段的长度> 0,改变按钮被禁用或没有。

Jquery would do that. On the .keyup event have jquery check if both field's lengths are > 0 and change the button to be disabled or not.

$('#yourButton').button("disable");​​​​​​​​​​​​​

$('.fields').bind('keyup', function() { 
var nameLength = $("#sub_first_name").length;
var emailLength = $("#sub_email").length;

if (nameLength > 0 && emailLength > 0)
{
   $('#yourButton').button("enable");​​​​​​​​​​​​​
}

} );

这篇关于灰色了提交按钮,直到表格填写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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