0

以前もこれと同じような質問がありましたが、ユーザーが気が変わったので修正しなければなりませんでした。オプション0が選択されている場合は「リマインダー」が表示され、それ以外の場合は非表示にされるスクリプトに取り組んでいます。オプション2が選択されている場合は、「cc」を再表示する必要があります。それ以外の場合は、非表示のままにします。私の問題は、オプション0または2に関係なくイベントが発生すると、両方の領域が開くことです。私はそれらを別々に動作させるためにいくつかの助けを得ることができるかどうか疑問に思っていました。これがJSです:

 $('#rbPType').change(function () {
 var op1 = $(this).attr('value', '0');
 var op2 = $(this).attr('value', '2');

 if (op1) {
    $('#remind').fadeIn();
 } else {
    $('#remind').fadeOut();
 }

 $(this).change(function () {
     $('#remind').toggle();
 });

 if (op2) {
     $('#cc').fadeIn();
 } else {
     $('#cc').fadeOut();
 }

 $(this).change(function () {
     $('#cc').toggle();
 });

 });

HTML

<div class="another">
<label for="rbPType">Select One</label>
<asp:RadioButtonList runat="server" ID="rbPType" ClientIDMode="Static">
    <asp:ListItem Value="0" Text="1"></asp:ListItem>
    <asp:ListItem Value="1" Text="2"></asp:ListItem>
    <asp:ListItem Value="2" Text="3"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div id="remind">
<label for="ddlReminderMonth">Remind Me</label>
<asp:DropDownList runat="server" ID="ddlReminderMonth" AppendDataBoundItems="true" AutoPostBack="false" />
</div>
<div id="cc">
<label for="ddlReminderMonth">Remind Me Two</label>
<asp:DropDownList runat="server" ID="ddlReminderMonth" AppendDataBoundItems="true" AutoPostBack="false" />
</div>
4

2 に答える 2

0

ここに不要なコードをたくさん書いていると思います。jqueryのトグルはブールパラメータを取ります。trueの場合は選択したフィールドが表示され、falseの場合は非表示になります。

    $('#rbPType').change(function () {
     var op1 = $(this).attr('value', '0');
     var op2 = $(this).attr('value', '2');
     $('#remind').toggle(op1);
     $('#cc').toggle(op2);
    });

これはあなたが探しているものですか?

于 2013-03-25T18:17:48.383 に答える
0

同じのドロップダウンリストを2つ持つことはできませんddlReminderMonth

トグルにより、クリックするとコントロールが表示されたり消えたりします。Toggleを使用すると、コードが非常に混乱します。

<div class="another">
    <label for="rbPType">
        Select One</label>
    <asp:RadioButtonList runat="server" ID="rbPType" ClientIDMode="Static">
        <asp:ListItem Value="0" Text="1"></asp:ListItem>
        <asp:ListItem Value="1" Text="2"></asp:ListItem>
        <asp:ListItem Value="2" Text="3"></asp:ListItem>
    </asp:RadioButtonList>
</div>
<div id="remind">
    <label for="ddlReminderMonth">
        Remind Me</label>
    <asp:DropDownList runat="server" ID="ddlReminderMonth1" AppendDataBoundItems="true"
        AutoPostBack="false" />
</div>
<div id="cc">
    <label for="ddlReminderMonth">
        Remind Me Two</label>
    <asp:DropDownList runat="server" ID="ddlReminderMonth2" AppendDataBoundItems="true"
        AutoPostBack="false" />
</div>


<script>
    $('#rbPType').change(function () {
        var value = $('#rbPType input:checked').val();

        if (value == '0') {
            $('#remind').fadeIn();
            $('#cc').fadeOut();
        }
        else if (value == '1') {
            // Show or hide
        }
        else { // value == '2'
            $('#remind').fadeOut();
            $('#cc').fadeIn();
        }
    }); 
</script>
于 2013-03-25T18:28:08.863 に答える