请有人帮忙。这个表单验证没有触发..这真的让我很沮丧。我是一名 PHP 开发人员而不是 JS,所以我在这方面有点挣扎,尽管这显然很简单。我只是想根据选中的删除框来验证表单。
单击提交时没有任何显示。它只是提交表单,所以它必须返回 true。
function deleteVal(chk) {
var chk;
// If the checkbox has been set to delete
if (chk.checked == "delete") {
var ok=confirm("You are about to delete the selected images below.\nAre you sure you want to do this?");
if (ok) {
// Submit
return true;
} else {
// Don't submit
return false;
}
}
// Delete box was not ticked so return true and submit form
return true;
}
</script>
<form action="" method="POST" onSubmit="return deleteVal(delete)">
<label>Delete images?</label><input type="checkbox" name="delete" value="delete" />
<input type="submit" name="submit" value="Submit" />
</form>