Javascript 基于选中的复选框列表项显示或隐藏一个或多个控件

Javascript 基于选中的复选框列表项显示或隐藏一个或多个控件,javascript,jquery,asp.net,vb.net,Javascript,Jquery,Asp.net,Vb.net,对不起,专家们,我今天花了一半时间在谷歌上搜索,但我可以找到任何有用的解决方案 <script type="text/javascript"> function ShowHide(chk, txt) { //Get the Textbox based on selected checkbox ctrltxt = document.getElementById(txt); //Check if checkbox is checke

对不起,专家们,我今天花了一半时间在谷歌上搜索,但我可以找到任何有用的解决方案

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
我有一个ID为ckRequestReview的checkboxList控件。此复选框列表控件有三项

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
我们的要求是,如果用户单击其中一个项目,则显示两个与之相关的文本框

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
如果用户选中所有三个复选框项,则显示所有六个文本框控件

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
到目前为止,只有三个在工作

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
以下是需要发生的事情:

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
在页面加载时,默认情况下,所有六个文本框控件都隐藏

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
用户选中职务复选框项,两个控件,txtitlechangetxtitle控件可见

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
或者用户检查支付范围复选框项,并显示两个控件,txtPayGrade更改txtPayGrade

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
或者用户选中Class复选框项和两个控件,txtClassSpecChangetxtclassion

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
或者用户选中所有三个复选框项,并且所有六个文本框控件都可见

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
到目前为止,在列出的六个文本框控件中,只有这三个控件工作正常:

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
HTML

<div class="input text" style="float: left;">
    <span style="text-align: left; font-size: x-large; float: left;">Requested Change:</span>
    <div style="float: left; margin-right: 10px; margin-left: 10px">
        <asp:TextBox ID="txtTitleChange" runat="server" placeholder="Job Title" Style="margin-right: 0px; width: 200px; display: none;" />&nbsp;
    </div>
    <div style="float: left; margin-right: 10px">
        <asp:TextBox ID="txtPayGradeChange" runat="server" placeholder="for Pay Range" Style="margin-right: 0px; width: 200px; display: none;" />&nbsp;
    </div>
    <div style="float: left; margin-right: 10px">
        <asp:TextBox ID="txtClassSpecChange" runat="server" placeholder="for Class" Style="margin-right: 0px; width: 200px; display: none;" />
    </div>
</div>
<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>

请求的更改:
当复选框被选中或未选中时,其他三个什么也不做。你知道我做错了什么吗

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
JS

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>

函数ShowHide(chk,txt){
//根据选中的复选框获取文本框
ctrltxt=document.getElementById(txt);
//检查复选框是否选中
如果(已检查){
//显示文本框
ctrltxt.style.display='block';
}否则{
//隐藏文本框
ctrltxt.style.display='none';
}
}
HTML

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>

要求审查:
职位名称
工资范围
等级

请求的更改:


正当理由

您正确地向JS传递了三个参数,但只处理了2个。换成这个

<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>
<script type="text/javascript">
    function ShowHide(chk, txt,txt2) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        ctrltxt2= document.getElementById(txt2);
        //Check if checkbox is checked or not
        if (chk.checked) {
           //Show the Textbox
           ctrltxt.style.display = 'block';
           ctrltxt2.style.display = 'block';
         } else {
           //Hide the textbox
           ctrltxt.style.display = 'none';
           ctrltxt2.style.display = 'none';
         }
     }

函数ShowHide(chk、txt、txt2){
//根据选中的复选框获取文本框
ctrltxt=document.getElementById(txt);
ctrltxt2=document.getElementById(txt2);
//检查复选框是否选中
如果(已检查){
//显示文本框
ctrltxt.style.display='block';
ctrltxt2.style.display='block';
}否则{
//隐藏文本框
ctrltxt.style.display='none';
ctrltxt2.style.display='none';
}
}

干得好。这就是我错过的。现在,我工作正常了。非常感谢您的帮助。stackoverflow经常帮助我,我很高兴能报答您的帮助。:)
<script type="text/javascript">
    function ShowHide(chk, txt) {
        //Get the Textbox based on selected checkbox
        ctrltxt = document.getElementById(txt);
        //Check if checkbox is checked or not
        if (chk.checked) {
            //Show the Textbox
            ctrltxt.style.display = 'block';
        } else {
            //Hide the textbox
            ctrltxt.style.display = 'none';
        }
    }
</script>