如何放置警报,如果行被拖放并掉落并未单击更新按钮?
我有一个表,其行是使用可排序属性拖动的,如下所述。
<script type="text/javascript">
$(function () {
$("#tblLookup1 tbody").sortable({
items: 'tr',
cursor: 'pointer',
axis: 'y',
dropOnEmpty: false,
start: function (e, ui) {
ui.item.addClass("selected");
},
stop: function (e, ui) {
ui.item.removeClass("selected");
},
receive: function (e, ui) {
$(this).find("tbody").append(ui.item);
}
});
});
</script>
现在,一旦拖动行,我创建了一个更新按钮,该按钮用于将新订单更新为数据库。
<input type="submit" class="btn CreateButtonColor" id="btnSave" value="Update"/>
现在,我希望有一个警报,如果用户拖动并丢弃行和忘记以单击更新,则如何发出警告,以便用户在不保存的情况下不能导航到其他页面?
警告像下面的那样,
if (confirm('Do you want to save the data before leaving?')) {
// Update code
}
else
{
// do nothing
}
我应该在何处放置上述代码块?
I have a table whose rows are made draggable using sortable property as mentioned below.
<script type="text/javascript">
$(function () {
$("#tblLookup1 tbody").sortable({
items: 'tr',
cursor: 'pointer',
axis: 'y',
dropOnEmpty: false,
start: function (e, ui) {
ui.item.addClass("selected");
},
stop: function (e, ui) {
ui.item.removeClass("selected");
},
receive: function (e, ui) {
$(this).find("tbody").append(ui.item);
}
});
});
</script>
Now, once rows are dragged and dropped I have created an update button which is used to update the new order to database.
<input type="submit" class="btn CreateButtonColor" id="btnSave" value="Update"/>
Now I wish to have an alert, if the user drags and drops the rows and forgots to click on update, how to put warning so that user cannot navigate to other pages without saving?
warning something like below
if (confirm('Do you want to save the data before leaving?')) {
// Update code
}
else
{
// do nothing
}
where shall I place the above block of code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要执行您需要的事情,请在掉落东西时在桌子上设置标志。当用户尝试离开页面时,您可以检查是否设置了该标志并显示警告:
To do what you require, set a flag on the table when something is dropped. When the user attempts to leave the page you can then check to see if that flag is set and display the warning: