我在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中。