doufeixi6014 2016-04-06 03:47
浏览 92

选中复选框时如何启用按钮

I have codes like this

<div class="checkbox">

            <input type="checkbox" id="checkme" value ="accept"/>
                        <label>I have read and agree to the terms and conditions</label>
                                    <p><input type="submit" name="submit" value="Order now!" id="sub1" disabled="disabled"/></p>

I was trying to put this Jscript below of codes:

<script>
$(document).ready(function() {
    var the_terms = $("#checkme");

    the_terms.click(function() {
        if ($(this).is(":checked")) {
            $("#sub1").removeAttr("disabled");
        } else {
            $("#sub1").attr("disabled", "disabled");
        }
    });
}); 
                        </script>

However it does not work at all. I already follow all guides on internet. Anyone can help what part i did wrong? Is there any additional codes beside these?'

Oh and this on php format

EDIT: Done this too

                                                    <script>
var checker = document.getElementById('checkme');
var sendbtn = document.getElementById('sub1');
checker.onchange = function() {
  sendbtn.disabled = !!this.checked;
};
                        </script>

But how do i change to disable when unchecked?

  • 写回答

2条回答 默认 最新

  • dongyied24121 2016-04-06 03:53
    关注

    Simply use jquery change event like this :

    $(document).ready(function() {
    
        $('#checkme').change(function() {
            if ($(this).is(":checked")) {
                $("#sub1").removeAttr("disabled");
            } else {
                $("#sub1").attr("disabled", "disabled");
            }
        });
    }); 
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料