RadioButton更改事件jquery
我为RadioButton change事件编写此事件。但对于第一次加载页面的计时器,它不起作用。为什么RadioButton更改事件jquery,jquery,asp.net-mvc,razor,Jquery,Asp.net Mvc,Razor,我为RadioButton change事件编写此事件。但对于第一次加载页面的计时器,它不起作用。为什么 //html mvc code @Html.RadioButtonFor(m => m.DigitalFile, false) خیر @Html.RadioButtonFor(m => m.DigitalFile, true) بله <script> $(function () { $("input[name='
//html mvc code
@Html.RadioButtonFor(m => m.DigitalFile, false) خیر
@Html.RadioButtonFor(m => m.DigitalFile, true) بله
<script>
$(function () {
$("input[name='DigitalFile']").change(function () {
var $this = $(this);
if ($this.val() == "True") {
$("#MapZoning").attr("disabled", false);
} else {
$("#MapZoning").attr("disabled", true);
}
});
});
</script>
//html mvc代码
@Html.RadioButtonFor(m=>m.DigitalFile,false)ª¥
@Html.RadioButtonFor(m=>m.DigitalFile,true)به
$(函数(){
$(“输入[name='DigitalFile']”)。更改(函数(){
var$this=$(this);
如果($this.val()=“True”){
$(“#MapZoning”).attr(“禁用”,false);
}否则{
$(“#地图分区”).attr(“禁用”,真);
}
});
});
我没听清你的问题。
。但是对于第一次加载页面,它不起作用。为什么?
如果您是说当页面加载时,mapZoning的属性不会更改,那是因为您只在数字文件中发生更改时调用该函数(例如,有人选中或取消选中)您是否已将代码包装到document ready handler中?是,它在我更改所选radiobutton后工作。是,我希望在页面加载中也设置此设置。如何操作?调用$(document)中的函数。ready(您的函数在此);不要从.change中删除函数,否则change将无效如何检查$this是否已选中?我添加了general if($this.is(':checked'))并解决了问题