简体   繁体   English

数组复选框显示一个新的div

[英]Array checkbox show a new div

I have some problems with a JavaScript code, because I show a new div if the person checked a checkbox, but if a checked another checkbox the div should disappear, but it does, here my code: 我的JavaScript代码存在一些问题,因为如果此人选中了一个复选框,则显示一个新的div,但是如果选中另一个复选框,则该div应该消失了,但确实如此,这是我的代码:

<script type="text/javascript">
    var checkDisplay = function(check, form) { //check ID, form ID
        form = document.getElementById(form), check = document.getElementById(check);
        check.onclick = function(){
            form.style.display = (this.checked) ? "block" : "none";
            form.reset();
        };
        check.onclick();
    };
</script> 

And this is the block of HTML: 这是HTML的块:

<div id="Opciones">
        <p style="display: inline-block;">Efectivo</p>&nbsp;&nbsp;<input type="checkbox" value="1" id="efe" name="check"/>
        <p style="display: inline-block;">Deposito</p>&nbsp;&nbsp;<input type="checkbox" value="2" id="depo" name="check"/>
    </div>

    <div id="deposi">
        <div class="row">
             <input type="checkbox"/>
        </div>
    </div>
<script type="text/javascript">
    checkDisplay("depo", "deposi");
</script>

just one of the checboxes should be marked, if is checked depo checkbox open a new div with a new imput and another things, but if a cheked efe chechbox the div that appeared before should be dissapear, In short, if a checkbox should appear within a form, but if under another, should disappear. 只是其中一个复选框应被标记,如果选中了depo复选框,则使用新的输入和其他内容打开一个新的div,但是如果选中的是efe复选框,则应该消失之前出现的div,简而言之,如果复选框应出现在其中一种形式,但如果在另一种形式下,则应消失。

the problem become when shows the div, if i select the other checkbox the form does not disappear 问题出现在显示div时,如果我选择其他复选框,则表单不会消失

Please... I need help with this code... If you have another code that be great! 请...我需要有关此代码的帮助...如果您还有其他很棒的代码!

The solution to this is create an and a and be related in a javascript to show when the value is the same and hide when it changes 解决此问题的方法是在JavaScript中创建和并与之关联,以在值相同时显示,并在值更改时隐藏

><select name="status" id="status">
>    <option value="">pick one...</option>
>    <option value="show">show</option>
>    <option value="hide">hide</option>
></select>
><div name="razordiv" id="razordiv">Hi!</div>
><script>$(document).ready(function() {
>        $("#razondiv").hide();
>        $("#status").change(function() {
>           if ($("#status").val() == 'show') {
>               $("#razondiv").show();
>           }
>           else {
>               $("#razondiv").hide();
>           }
>        });
>     });
></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM