当用户选择“教堂”选择“否”时,我试图禁用表单中所需的消息。 所以基本上,它只需要隐藏 Chapel 下拉菜单,并且应该正常提交表单。当我单击单选按钮“否”并填写表格并按下“提交”按钮时,内容消失并显示所需的消息。 所以我的代码如下:
$(document).ready(function() {
$("input[name$='Chapel']").click(function() {
var test = $(this).val();
if (test == 'No') {
$("div#hideChapel").hide();
} else {
$("div#hideChapel").show();
}
});
});
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function() {
history.pushState(null, null, document.URL);
});
function ifChapelIsNo() {
var radionbutton_No = document.getElementById('No');
var radioButton_Yes = document.getElementById('Yes');
if (radioButton_Yes = true) {
window.location.href = '/ContractViewModels/ManualPayment';
} else if (radionbutton_No == true) {
window.location.href = '/ContractViewModels/ManualPayment';
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-9">
<label class="radio-inline">
<div class="choice" id="uniform-Yes"><span><input class="styled" htmlattributes="{ checked = true }" id="Yes" name="Chapel" type="radio" value="Yes" autocomplete="off"></span></div>
Yes
</label>
<label class="radio-inline">
<div class="choice" id="uniform-No"><span class="checked"><input checked="checked" class="styled" htmlattributes="{ checked = true }" id="No" name="Chapel" type="radio" value="No" autocomplete="off"></span></div>
No
</label>
<span class="field-validation-valid text-danger" data-valmsg-for="Chapel" data-valmsg-replace="true"></span>
</div>
我认为错误出在 HTML 中的某个地方,也许我错过了一些要定义的 ID 或值
图片
最佳答案
您的代码中似乎存在拼写错误。您使用 =
进行比较,而应该是 ==
或 ===
if (radioButton_Yes = true) { // ---------- over here
window.location.href = '/ContractViewModels/ManualPayment';
}
关于JavaScript 禁用所需消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50813055/