我很感激以前曾经问过这个问题,但我尝试了各种各样的例子。不能让这个工作,所以建议将不胜感激。我得到的最近的是下面的代码,根据需要删除了禁用的属性,但如果删除了勾号,我希望它再次被禁用(我意识到这是因为在我的例子中没有代码可以执行此操作,但我尝试了其他各种方法我将在下面显示,这将无法正常工作)。感谢
<div class="form-group" id="deleteCheck" type="checkbox">
@Html.LabelFor(m => m.Notification.DeleteFlag)
@Html.CheckBoxFor(m => m.Notification.DeleteFlag)
<div class="form-group">
<button type="submit" class="btn btn-primary" formaction="DeleteSubmit" id="submitDelete" disabled>Submit</button> <button type="submit" class="btn btn-primary" formaction="~/Home/Index" id="retrieve">Cancel</button>
@Html.HiddenFor(m => m.Notification.Id)
@Html.AntiForgeryToken()
}
@section scripts
{
<script>
$(function () {
$('#deleteCheck').click(function () {
$('#submitDelete').removeAttr('disabled');
});
});
</script>
其他例子:
@section scripts
{
<script>
var deletecheck = document.getElementById("submitDelete").disabled = true;
var submitbtn = document.getElementById("deleteCheck");
deletecheck.onchange = function () {
submitbtn.enabled = !!this.checked;
};
</script>
}
和
<div class="form-group" id="deleteCheck" type="checkbox">
@Html.LabelFor(m => m.Notification.DeleteFlag)
@Html.CheckBoxFor(m => m.Notification.DeleteFlag)
<div class="form-group">
<button type="submit" class="btn btn-primary" formaction="DeleteSubmit" id="submitDelete">Submit</button> <button type="submit" class="btn btn-primary" formaction="~/Home/Index" id="retrieve">Cancel</button>
@Html.HiddenFor(m => m.Notification.Id)
@Html.AntiForgeryToken()
}
@section scripts
{
<script>
$(function () {
$('#deleteCheck').click(function () {
if ($(this).is(':checked')) {
$('#submitDelete').attr('disabled', 'disabled');
} else {
$('#submitDelete').removeAttr('disabled');
}
});
});
</script>
}