我需要根据特定条件停止标签更改的默认行为。我的问题是,一旦我在我的标签上发出.preventDefault()
,我就无法更改为用户在.beforeActivate
事件之前要去的标签。我正在使用jQuery messagebox插件,在用户确认之前无法暂停代码。
<script>
$("#tabs").tabs({});
</script>
<div id="tabs">
<ul>
<li><a href="ajax/divs/tabbed/tripinfo.php?id=<?php echo $_REQUEST["id"]; ?>">Schedule</a></li>
<li><a href="ajax/divs/tabbed/tripinfo_expenses.php?id=<?php echo $_REQUEST["id"]; ?>">Expenses</a></li>
<li><a href="ajax/divs/tabbed/tripinfo_fuel.php?id=<?php echo $_REQUEST["id"]; ?>">Fuel Log</a></li>
<li><a href="ajax/divs/tabbed/equipment_info.php?id=<?php echo $_REQUEST["id"]; ?>">Equipment</a></li>
<li><a href="ajax/divs/tabbed/tripinfo_route.php?id=<?php echo $_REQUEST["id"]; ?>">Route Configuration</a></li>
</ul>
</div>
<script>
var rows = $("#numbered tbody tr").not(":last").length;
$("#tabs").tabs({
beforeActivate: function (event, ui) {
// If user exits without saving alert
if (rows != $("#numbered tbody tr").not(":last").length) {
event.preventDefault();
$.confirm('YOU HAVE MADE CHANGES TO THIS ROUTE. ARE YOU SURE YOU WANT TO LEAVE THE PAGE? ALL CHANGES WILL BE LOST!' , function (answer) {
if (!answer) {
return false;
} else {
// User agrees so swicth tabs so take him to the one he requested.
$("#tabs").tabs("option", "active", ui.newTab.index());
}
});
}
}
})
</script>