English 中文(简体)
如何检查/检查另一个检查箱的国家检查/检查情况
原标题:How to check/uncheck a checkbox based on the state check/uncheck of another checkbox
  • 时间:2010-11-16 18:25:36
  •  标签:
  • jquery

Guys试图检查/检查另一个检查箱的国家检查/检查箱。 并且试图为这里的每个检查箱打造一个吉克文。

从根本上说,如果对“客户领域[12_1]_la1”进行检查,则要检查“名单1”的状况。 此外,还确定了在“外地[12_1]_la1”时不予检查的地位。

And the same for the rest: so the correlations are: CustomFields[12_1]_la1 ---> lists_1 CustomFields[12_1]_la2 ---> lista_2 and on and on...

NOTE: i CANT change the name of the ids.

<td><span class="required">*</span>&nbsp;
concesionarias:</td>
    <td><label for="CustomFields[12_1]_la1"><input type="checkbox"     id="CustomFields[12_1]_la1" name="CustomFields[12][]" value="la1">la1</label><br/><label     for="CustomFields[12_1]_la2"><input type="checkbox" id="CustomFields[12_1]_la2"     name="CustomFields[12][]" value="la2">la2</label><br/><label for="CustomFields[12_1]_la3">    <input type="checkbox" id="CustomFields[12_1]_la3" name="CustomFields[12][]"     value="la3">la3</label><br/><label for="CustomFields[12_1]_la4"><input type="checkbox"     id="CustomFields[12_1]_la4" name="CustomFields[12][]" value="la4">la4</label><br/></td>
</tr><tr>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;Contact Lists:</td>
    <td><label for="lists_1"><input type="checkbox" id="lists_1" name="lists[]"     value="1" />&nbsp;ddsd</label></td>
</tr><tr>
    <td>&nbsp;</td>
    <td><label for="lists_2"><input type="checkbox" id="lists_2" name="lists[]"     value="2" />&nbsp;laconce1</label></td>
</tr><tr>
    <td>&nbsp;</td>
    <td><label for="lists_3"><input type="checkbox" id="lists_3" name="lists[]"     value="3" />&nbsp;laconce2</label></td>
</tr><tr>
    <td>&nbsp;</td>
    <td><label for="lists_4"><input type="checkbox" id="lists_4" name="lists[]"     value="4" />&nbsp;laconce3</label></td>
</tr><tr>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;ESTADO:</td>
    <td><select name="CustomFields[13]" id="CustomFields_13_1"><option value="">--      Please choose an option --</option><option value="Contacto">Contacto</option><option     value="Oportunidad">Oportunidad</option><option value="Vendido">Vendido</option></select>    </td>
</tr><input type="hidden" name="format" value="h" />
        <tr>
            <td></td>
            <td>
                <input type="submit" value="Subscribe" />
                <br/>
            </td>

这是经过描述的尝试,它有活力。

<script type="text/javascript">
$(document).ready(function(){
        $("#CustomFields[12_1]_la1").click(function() {
               if ($("CustomFields[12_1]_la1").attr("checked") == true) {
                $("lists_1").attr( checked , true);
                } else if ($("CustomFields[12_1]_la1").attr("checked") == false) {
                 $("lists_1").attr( checked , false);
                }
        });
    });
</script>

没有人能够建议开展新的工作,争取达到什么目标? 感谢大家

最佳回答
问题回答

you re not referencing the checkboxes properly, need to use class or ID

  <script type="text/javascript">
    $(document).ready(function(){
            $("#CustomFields[12_1]_la1").click(function() {

                    $("#lists_1").attr( checked , $(this).attr("checked"));
                    $("#lists_2").attr( checked , $(this).attr("checked"));
                    $("#lists_3").attr( checked , $(this).attr("checked"));
                   $("#lists_4").attr( checked , $(this).attr("checked"));

            });
        });
    </script>

如果你能给他们一个共同的阶层,你可以:

  <script type="text/javascript">
    $(document).ready(function(){
            $("#CustomFields[12_1]_la1").click(function() {

                    $(".lists_all").attr( checked , $(this).attr("checked"));

            });
        });
    </script>

对改变事件而不是点击事件有约束力。 因此,你正在根据点击后变件的价值更新相关的核对箱。

function change_handler(e) {
    var $t = $(e.target),
        t_is_checked = $t.is( :checked ),
        list_number = $t.attr( id ).split( _ ).reverse()[0].splice(2),
        related_item_id = "#list_" + list_number,
        related_item = $(related_item_id);
    related_item.attr( checked , t_is_checked ?    :  checked );
}

// bind to all your target input fields (maybe give them a class for easy selection)
// (just binding one for this example)

$("#CustomFields[12_1]_la1")
    //.unbind( change ) // really handy if you are testing the code via console
    .bind( change , change_handler)
    .change(); // trigger a bogus change event to setup the initial checkbox state




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...