-3

Los Frijoles 先生请展示我的问题和答案。怎么可能。?我有 2 个下拉菜单,第一个是静态的“drpDisplayAns1”,第二个是“drpCorrectAns1”,在这里我选择“drpDisplayAns1”选项 2,然后我在第二个下拉菜单的“drpCorrectAns1”中只得到 1 和 2,或者我选择 3,然后我只得到1、2 和 3 在“drpCorrectAns1”我的第二个下拉菜单中,或者我选择 4 然后我在“drpCorrectAns1”我的第二个下拉菜单中得到 1、2、3 和 4。表示使用 jquery 添加运行时。或等等,怎么可能。?在 Mvc 剃刀中。请帮助我。谢谢。

我的视图代码是

         '<div class="editor-field">
         @Html.DropDownListFor(model => model.DisplayAnswer, new SelectList(new[]
                                      {
                                          new { value="2", text="2"},
                                          new { value="3", text="3"},
                                          new { value="4", text="4"},
                                      }, "value", "text", 4), new{ id= 

   "drpDisplayAns1"})'
        '@Html.ValidationMessageFor(model => model.DisplayAnswer)
    </div>
    <div class="editor-label1">
        @Html.LabelFor(model => model.Answer1)

        @Html.EditorFor(model => model.Answer1)
        @Html.ValidationMessageFor(model => model.Answer1)
    </div>
    <div class="editor-label2">
        @Html.LabelFor(model => model.Answer2)

        @Html.EditorFor(model => model.Answer2)
        @Html.ValidationMessageFor(model => model.Answer2)
    </div>
    <div class="editor-label3">
        @Html.LabelFor(model => model.Answer3)

        @Html.EditorFor(model => model.Answer3)
        @Html.ValidationMessageFor(model => model.Answer3)
    </div>
    <div class="editor-label4">
        @Html.LabelFor(model => model.Answer4)

        @Html.EditorFor(model => model.Answer4)
        @Html.ValidationMessageFor(model => model.Answer4)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.CorrectAnswer)
    </div>
   <div class="editor-field">
        @Html.DropDownListFor(model => model.CorrectAnswer, new SelectList(new[]
                                      {
                                          new {value="0", text=" "},
                                          new {value="1", text="1"},
                                          new {value="2", text="2"},
                                          new {value="3", text="3"},
                                          new {value="4", text="4"},
                                      }, "value", "text", 0), new{id="drpCorrectAns1"})
        @Html.ValidationMessageFor(model => model.CorrectAnswer)
    </div>'

和脚本文件

'$(document).ready(function () {
$('#drpDisplayAns1').change(function () {

    if (this.value == '2') {
        $('.editor-label1').show();
        $('.editor-label2').show();
        $('.editor-label3').hide();
        $('.editor-label4').hide();
    }
    else if (this.value == '3') {
        $('.editor-label1').show();
        $('.editor-label2').show();
        $('.editor-label3').show();
        $('.editor-label4').hide();
    }

    else if (this.value == '4') {
        $('.editor-label1').show();
        $('.editor-label2').show();
        $('.editor-label3').show();
        $('.editor-label4').show();
    }
});

});'

4

1 回答 1

1

Mr.Los Frijoles 我不会问假问题。

我的问题的答案如下。汝了解先生。洛斯弗里霍勒斯..??

    <div class="editor-field">
     @Html.DropDownListFor(model => model.DisplayAnswer, new SelectList(new[]
                                  {
                                      new { value="2", text="2"},
                                      new { value="3", text="3"},
                                      new { value="4", text="4"},
                                  }, "value", "text", 4), new{ id= 

"drpDisplayAns1"})'
    '@Html.ValidationMessageFor(model => model.DisplayAnswer)
</div>
<div class="editor-label1">
    @Html.LabelFor(model => model.Answer1)

    @Html.EditorFor(model => model.Answer1)
    @Html.ValidationMessageFor(model => model.Answer1)
</div>
<div class="editor-label2">
    @Html.LabelFor(model => model.Answer2)

    @Html.EditorFor(model => model.Answer2)
    @Html.ValidationMessageFor(model => model.Answer2)
</div>
<div class="editor-label3">
    @Html.LabelFor(model => model.Answer3)

    @Html.EditorFor(model => model.Answer3)
    @Html.ValidationMessageFor(model => model.Answer3)
</div>
<div class="editor-label4">
    @Html.LabelFor(model => model.Answer4)

    @Html.EditorFor(model => model.Answer4)
    @Html.ValidationMessageFor(model => model.Answer4)
</div>
<div class="editor-label">
    @Html.LabelFor(model => model.CorrectAnswer)
</div>
<div class="editor-field">
    @Html.DropDownListFor(model => model.CorrectAnswer, new SelectList(new[]
                                  {
                                      new {value="0", text=" "},
                                      new {value="1", text="1"},
                                      new {value="2", text="2"},
                                      new {value="3", text="3"},
                                      new {value="4", text="4"},
                                  }, "value", "text", 0), new{id="drpCorrectAns1"})
    @Html.ValidationMessageFor(model => model.CorrectAnswer)
</div>

我的脚本代码是:

  $(document).ready(function () {
  $('#drpDisplayAns1').change(function () {

    if (this.value == '2') {
        $('.editor-label1').show();
        $('.editor-label2').show();
        $('.editor-label3').hide();
        $('.editor-label4').hide();
        $("#drpCorrectAns1 option[value='3']").attr("disabled", true).hide();
        $("#drpCorrectAns1 option[value='4']").attr("disabled", true).hide();
    }

    if (this.value == '3') {
        $('.editor-label1').show();
        $('.editor-label2').show();
        $('.editor-label3').show();
        $('.editor-label4').hide();
        $("#drpCorrectAns1 option[value='3']").attr("disabled", false).show();
        $("#drpCorrectAns1 option[value='4']").attr("disabled", true).hide();
    }

     if (this.value == '4') {
       $('.editor-label1').show();
       $('.editor-label2').show();
       $('.editor-label3').show();
       $('.editor-label4').show();
       $("#drpCorrectAns1 option[value='3']").attr("disabled", false).show();
       $("#drpCorrectAns1 option[value='4']").attr("disabled", false).show();
   }
});
于 2013-07-19T07:10:16.540 回答