gpt4 book ai didi

javascript - 无法在确认框中获取更新的全局变量值

转载 作者:行者123 更新时间:2023-12-03 12:25:57 25 4
gpt4 key购买 nike

 <script type="text/javascript">
var customDiv ="hello";
$(function () {
var $form = $("#authNotificationForm");

var startItems = $form.serializeArray();
startItems = convertSerializedArrayToHash(startItems);

$("#authNotificationSubmit").click(function (e) {
var currentItems = $form.serializeArray();
currentItems = convertSerializedArrayToHash(currentItems);

var itemsToSubmit = hashDiff(startItems, currentItems);

for (var item in itemsToSubmit) {
customDiv = "test";
}
});

$(".confirm").confirm({
text: "Are you sure you want update the following changes?" + customDiv,
confirm: function (button) {
// do something
},
cancel: function (button) {
// do something
},
confirmButton: "Yes I am",
cancelButton: "No",
post: true
});
</script>

我想做的就是在表单加载时获取表单的serializeArray。然后,在提交时再次更改字段后,单击“获取新的表单序列化数组”,比较这两个字段并获取已更改的字段,然后在确认框中仅显示用户更改的字段。但确认框显示的是 hello 而不是 test。我的假设是,确认框文本已在文档就绪时加载,并且从未更新,因此它始终具有在文档就绪时设置的全局变量值。(我正确地获取了更新的值,因此序列化和 hashDiff 函数都很好,这不是问题,问题只是将此值发送到确认框。)谢谢关心..

最佳答案

您正在加载时设置 text: 选项。稍后更改 customDiv 不会影响它,因为串联已在之前完成。

不要将确认对话框直接绑定(bind)到按钮,而是使用 $.confirm 以便您可以在调用时传递参数:

$(".confirm").click(function() {
$.confirm({
text: "Are you sure you want update the following changes?" + customDiv,
confirm: function (button) {
// do something
},
cancel: function (button) {
// do something
},
confirmButton: "Yes I am",
cancelButton: "No",
post: true
});
});

关于javascript - 无法在确认框中获取更新的全局变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24209987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com