-1

複数のテキストボックスを有効にするチェックボックスを作成しています。チェックすると、デフォルトで有効または無効になります。

Javascript コード :

$(document).ready(function(){
    $('#sccb').click(function(){
        if (this.checked) {
            $('#cns').removeAttr("disabled");
            $('#cns2').removeAttr("disabled");
            $('#cns3').removeAttr("disabled");
        } else {
            $("#cns").attr("disabled", true);
            $("#cns2").attr("disabled", true);
            $("#cns3").attr("disabled", true);
        }
    });
});

HTML コード :

<input type="checkbox" id="sccb" name="science" value="science">
<input type="text" id="cns" name="coornamescience" disabled="disabled" size="30" />
<input type="text" id="cns2" name="coornamescience" disabled="disabled" size="30" />
<input type="text" id="cns3" name="coornamescience" disabled="disabled" size="30" />

jsfiddle では動作しますが、.html ファイルでは動作しません。助けてください。

4

1 に答える 1

2

jquery を追加するのを忘れましたか?

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#sccb').click(function(){
        if (this.checked) {
            $('#cns').removeAttr("disabled");
            $('#cns2').removeAttr("disabled");
            $('#cns3').removeAttr("disabled");
        } else {
            $("#cns").attr("disabled", true);
            $("#cns2").attr("disabled", true);
            $("#cns3").attr("disabled", true);
        }
    });
});
</script>
</head>
<body>
    <form ...>
         Your form here
    </form>
</body>
</html>
于 2013-04-23T10:00:42.283 に答える