{ field: "Accept", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.AcceptChk), "template": "<input type=\"checkbox\" # if (checkCommentsAccept(data.Comments)) { #disabled=\"disabled\" # } # />" },
{ field: "Decline", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.DeclineChk), "template": "<input type=\"checkbox\" # if (checkCommentsDecline(data.Comments)) { #disabled=\"disabled\" # } # />" },
{ field: "Item", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Item) },
{ field: "PartID", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.PartID) },
{ field: "Description", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Description), width: '300px' },
{ field: "SubPart", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPart) },
{ field: "SubPartDescription", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPartDescription) },
{ field: "BusinessPartner", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.BusinessPartner) },
{ field: "ReqDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.ReqDelTM) },
{ field: "EarDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.EarDelTM) },
{ field: "EarDelDate", title: "Ear Del Date", hidden: true },
{ field: "Comments", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Comments) }
当我点击submit按钮时,它应该检查accept复选框是否被选中,如果被选中,那么我有一些逻辑。如果选中了拒绝复选框,则我有其他一些逻辑。
发布于 2019-09-26 04:37:08
这实际上归结为如何阻止事件执行其本机行为。
如果按下submit按钮,则会触发表单的submit
事件。因此,如果您的复选框当时没有被选中,您将需要停止该事件,这是通过event.preventDefault()
完成的。如果复选框被选中,那么简单地什么也不做,并允许提交发生。
下面是一个例子:
// Get reference to the checkbox
let chk = document.querySelector("input[type='checkbox']");
// Set up event handler on the form
document.querySelector("form").addEventListener("submit", function(event){
// Check to see if the checkbox was not checked
if(!chk.checked){
event.preventDefault(); // Stop the submit event
alert("You must agree before continuing.");
return;
}
// If we get to this point in the code, the checkox was checked
// and the form will submit.
});
<form action="http://example.com" method="post">
<input type="checkbox" name="chkAgree"
id="chkAgree" value="agree">
I agree to the terms of this site.
<br>
<button>Submit</button>
</form>
发布于 2019-09-26 05:22:06
如果有复选框,您可能已经实现了仅选中单个复选框,否则可能会选中接受和拒绝两个复选框,
假设您已经实现了单选复选框逻辑
$( "form" ).submit(function( event ) {
event.preventDefault();
if($("input[type='checkbox']:checked")[0].val() == 'Allow'){
// things to done on allowed
}else if($("input[type='checkbox']:checked")[0].val() == 'Declined'){
// things to done on declined
}else{
// rest things
}
});
您可能需要稍微更改代码,但从逻辑上讲,它将根据您的需要工作。
https://stackoverflow.com/questions/58109531
复制相似问题