Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选中checbox时如何启用按钮_Javascript_Php_Jscript - Fatal编程技术网

Javascript 选中checbox时如何启用按钮

Javascript 选中checbox时如何启用按钮,javascript,php,jscript,Javascript,Php,Jscript,我有这样的代码 <div class="checkbox"> <input type="checkbox" id="checkme" value ="accept"/> <label>I have read and agree to the terms and conditions</label> <

我有这样的代码

<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>

我已阅读并同意条款和条件

我试图将这个Jscript放在下面的代码中:

<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>

$(文档).ready(函数(){
var the_terms=$(“#checkme”);
_术语。单击(函数(){
如果($(this).is(“:checked”)){
$(“#sub1”).removeAttr(“禁用”);
}否则{
$(“#sub1”).attr(“禁用”、“禁用”);
}
});
}); 
然而,它根本不起作用。我已经遵守了互联网上的所有指南。谁能帮我什么忙我做错了?除此之外还有其他代码吗?”

哦,这是php格式的

编辑: 我也这么做了

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

var checker=document.getElementById('checkme');
var sendbtn=document.getElementById('sub1');
checker.onchange=函数(){
sendbtn.disabled=!!this.checked;
};

但我如何在取消选中时更改为禁用?

只需像这样使用jquery更改事件:

$(document).ready(function() {

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

只需像这样使用jquery更改事件:

$(document).ready(function() {

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

您能检查一下您的控制台是否有任何错误吗?请告诉我:您是否包括jquery库?jquery库?抱歉,我刚开始编程,所以我不知道如果你要使用jquery,你必须包括jquery库,你需要从一些基础开始:现在就可以了。谢谢shubham:)你能检查一下你的控制台是否有任何错误吗工作:你包括jquery库了吗?jquery库?抱歉,我刚开始编程,所以我不知道如果你要使用jquery,你必须包括jquery库,你需要从一些基础开始:现在就可以了。谢谢shubham:)如果您认为另一个答案完整地涵盖了这个问题,您可以将其标记为重复,而不是复制答案。除非你的答案是链接答案的修改版本,但事实并非如此。如果你认为另一个答案完整地涵盖了这个问题,你可以将其标记为重复,而不是复制答案。除非你的答案是链接答案的修改版本,但事实似乎并非如此。