自定义警报与复选框- Javascript
Custom alert with Checkbox - Javascript
我试图得到一个警报弹出,其中有一个复选框,用户需要检查,并单击提交继续。
我使用div标签来定义必须在警报上显示的警报消息,然后编写一些java脚本来返回值。
mydiv tag with alert message:
<div id="confirm_popup" style="color:red">
<input type="checkbox" id="myCheckBox" /> Check in to confirm the following actions to take place and click OK
<div style="margin-top: 15px; font-weight: bold; color:red; ">
<p>* You will not be able to make additional changes to your current reporting period. It is very important to review your credits. </p>
<p>* A new two-year reporting period tab will open. </p>
</div>
</div>
javascript代码:
<script type="text/javascript">
$('#close_record').submit(function() {
var status = false
$("#confirm_popup").html("Hi message!!!").dialog({
modal: true,
title: 'Alert Message', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Ok: function () {
$(this).dialog("close");
if ($('#myCheckBox').is(":checked")){
status = true
}
},
},
close: function (event, ui) {
$(this).remove();
}
});
if(status == true){
return true
}
else {
false
}
})
</script>
close_record是我有提交按钮的表单的id。我使用表单提交动作来触发弹出的javascript。
但由于某种原因,这不起作用。我已经尝试了我能想到的所有可能的方法,但没有任何帮助。任何帮助都是感激的!
谢谢
您需要在对话框关闭后触发submit
事件。
在OK函数中,你需要检测复选框,然后像这样做:
$('#yourForm').trigger('submit');
避免异步方法中的变量,值不会是你需要的或你想的。
试试这个:
<form id="close_record">
<input type="checkbox" style="display: none" id="myCheckBoxForm" />
<input type="submit" value="go" />
</form>
<div id="confirm_popup" style="color:red">
<input type="checkbox" id="myCheckBox" />Check in to confirm the following actions to take place and click OK
<div style="margin-top: 15px; font-weight: bold; color:red; ">
<p>* You will not be able to make additional changes to your current reporting period. It is very important to review your credits.</p>
<p>* A new two-year reporting period tab will open.</p>
</div>
</div>
和JS:
$('#close_record').submit(function (e) {
if ($('#myCheckBoxForm').is(":checked")) {
return true;
} else {
e.preventDefault();
}
$("#confirm_popup").dialog({
modal: true,
title: 'Alert Message',
zIndex: 10000,
autoOpen: true,
width: 'auto',
resizable: false,
buttons: {
Ok: function () {
$(this).dialog("close");
$('#myCheckBoxForm').prop('checked', $('#myCheckBox').prop('checked'));
},
}
});
})
相关文章:
- Javascript复选框函数:;缺少:在属性id之后"
- 潜水没有在Bootstrap/Javascript复选框菜单中排队
- JavaScript 复选框全选、取消全选、反转选择
- 单击离开时选中的 JavaScript 复选框
- Javascript复选框验证:如果用户没有't选中特定复选框
- Javascript复选框逻辑错误
- Javascript复选框填充输入并将不同的值传递给表单
- 简单的 JavaScript 复选框验证
- JavaScript 复选框表 - 如何添加值并查找最高值
- Ajax JavaScript 复选框更改不起作用
- Javascript 复选框表单验证
- 使用 JavaScript 复选框事件切换 html 的可见性
- JavaScript - 复选框的作用类似于单选按钮
- jQuery / JavaScript 复选框显示多个和单个选择中选中的复选框的数量
- javascript 复选框 - 仅在引导模式确定时取消选中
- 设置 JQuery HTML javascript 复选框工作,但不显示为选中状态
- Javascript复选框已选中触发器问题
- Javascript复选框的问题
- Javascript复选框递增和递减
- Javascript-复选框onclick-+操作