dqqg0811 2015-03-14 12:17
浏览 44
已采纳

当文本框中包含数据时禁用按钮

I see so many people ask to disable a button when a textbox is empty . how about disable a button when a textbox has data ?

this is my button code

<input type="submit" name="submit" value="Reserve" />

this is my textbox code

Name : <br><br><input type="text" name="name" value="<?php echo $name;?>"     <?php if($name != "") echo "readonly"?> /> <br><br>

Name : <br><br><input type="text" name="name2" value="<?php echo $name2;?>" <?php if($name2 != "") echo "readonly"?> /> <br><br>
  • 写回答

1条回答 默认 最新

  • douqiju2520 2015-03-14 12:26
    关注
    <input type="submit" name="submit" value="Reserve" <?php echo ($name != "")?"disabled":""; ?>/> 
    

    Using jQuery

    $(":input").bind('keyup mouseup',function(){   
        disable_button();
    });
    
    function disable_button()
    {
        flag = false;
        $(":input").each(function(){
           if($(this).val()==""){
              flag=true;
           }
       });
       if(flag){
          $("input[type=submit]").prop("disabled",false);
       }
       else
       {
         $("input[type=submit]").prop("disabled",true);
      } 
    }
    

    Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信
    • ¥15 使用QT实现can通信
    • ¥15 关于sp验证的一些东西,求告知如何解决,
    • ¥35 关于#javascript#的问题:但是我写的只能接码数字和字符,帮我写一个解码JS问题