选中/取消选中时启用/禁用文本框 [英] Enable/disable text box on check/uncheck

查看:64
本文介绍了选中/取消选中时启用/禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字段,点击该复选框可启用和禁用文本框。



默认情况下,选中此框。



我有以下代码。取消选中该框后,显示屏将被禁用。但是,当我再次检查时,它仍然保持禁用状态。



有人可以告诉我我做错了吗。





任何帮助表示赞赏。

I have a input field and on clicking that checkbox it enables and disables the text box.

By default, the box is checked.

I have the following code. Once i uncheck that box, the display is disabled. However, when i check it again, it still remains disabled.

Can someone please tell me where i am doing it wrong.


Any help is appreciated.


谢谢。



我的尝试:



Thank you.

What I have tried:

<input type="checkbox" class="show-check" checked value="1" id="DisplayOnClick">







document.getElementById("DisplayOnClick").onclick = function(){
        if(document.getElementById("DisplayOnClick").checked){
            document.getElementById("myFieldset").style.display = "block";
           
        } else {       
            document.getElementById("myFieldset").disabled = !this.checked;          
        }
    }







$(function () {

        $("#DisplayOnClick").click(function () {
            if ($(this).is("checked")){
                $("#myFieldset").show();
            }else {
                $("#myFieldset").hide();
            }
        });
    });

推荐答案

(function(){
(function () {


(#DisplayOnClick)。click(function(){
if(
("#DisplayOnClick").click(function () { if (


(this).is(checked)){
(this).is("checked")){


这篇关于选中/取消选中时启用/禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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