我的網頁上有一個按鈕和複選框(使用條款)。
如果未選中該複選框,則應該禁用該按鈕。未在網頁加載時觸發複選框更改
我想重置每個負載的情況。 (第一次加載或使用後退btn等)復位狀態是:複選框不應該被檢查,並且btn被禁用。 但是,當我單擊複選框而不是在加載時調用該函數。 更新:我也測試了.trigger('change')
。據我以前不工作太
$(function() {
$('#termsOfUse').removeAttr('checked');
$('#termsOfUse').change();
$('#termsOfUse').change(function() {
if ($(this).is(":checked")) {
$('#createBtn').prop('disabled', false);
} else {
$('#createBtn').prop('disabled', true);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<input id="termsOfUse" type="checkbox" />
<label for="termsOfUse" style="display: inline;">
<span><a href="/rules">rules</a></span> I am agree with</label>
</div>
<div class="create">
<input id="createBtn" type="button" value="create" class="btn btn-default btn-success"
onclick="location.href = '@Url.Action("Create","NewOne ")'" />
</div>
使用'$(文件)。就緒(函數(){你的代碼})' –
移動$(」 #termsOfUse')改變();事件處理程序分配 – mplungjan
@amirhoseinahmadi OP已經在做 –