如果文本框突然具有值,如何无法按钮 [英] How to unable button if textbox suddenly have values

查看:64
本文介绍了如果文本框突然具有值,如何无法按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的texbox突然充满文本而没有单击文本框来输入内容,谁能帮助我如何禁用按钮.

Can anyone help me how to make my button disable if my texbox suddenly filled with text without clicking the textbox to input something.

我的问题是我的代码无法正常工作.有谁知道该怎么做.

My problem is my code wont work. Does anyone know how to do it.

<form method="post">
<input type="text" name="name1" id="name1" class="number" />
<input type="text" name="name2" id="name2" class="number" />
<input type="submit" name="send" id="send" class="hey" value="one" disabled />
</form>

脚本代码:

<script>
$(document).ready(function () {
  $('.number').blur(function () {
        if ($.trim(this.value) == "") {
          $('#send').attr("disabled", true);
        }
      else {
            $('#send').removeAttr("disabled");
      }
    });
});
</script>

推荐答案

为了安全起见,可以结合使用输入,模糊和抠像事件:

You can use combination of input, blur and keyup events to be safe:

$('.number').on('keyup blur input', function () {
    $('#send').prop("disabled", !$.trim(this.value));
});

这篇关于如果文本框突然具有值,如何无法按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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