更改功能不会在Razor视图中的dropdownlistFor更改时触发

时间:2019-05-17 21:40:32

标签: javascript c# jquery asp.net-mvc razor-pages

我在Razor视图中有一个dropdownListFor,我希望更改值时能够触发Jquery change函数。

下拉式剃刀代码

 <li id="servicesOffer"><a data-toggle="pill" href="#services" hidden>Services Offered</a></li>

 <div class="form-group">
      @Html.LabelFor(model => model.CustomerProfile.CustomerTypeId, "Customer Type", htmlAttributes: new { @class = "control-label col-md-2" })

      <div class="col-md-10">
           @Html.DropDownListFor(model => model.CustomerProfile.CustomerTypeId, Model.CustomerProfile.CustomerTypeList, htmlAttributes: new { @class = "form-control spCheck"})
           @Html.ValidationMessageFor(m => m.CustomerProfile.CustomerType.CustomerTypeId, "", new { @class = "text-danger" })
      </div>
 </div>

jQuery代码


<script>
    $(document).ready(function () {
        $('.spCheck').change(function () {
            if ($('.spCheck').val() == 1 || $('.spCheck').val() == 3) {
                $("servicesOffer").attr("hidden", false)
            }
            else {
                $("servicesOffer").attr("hidden", false)
            }
        });
    });
</script>

我想在我的jquery中调用change函数,所以我将hidden属性添加到li中。

0 个答案:

没有答案