jQuery选项卡在.preventDefault()之后更改选项卡

时间:2016-02-14 07:07:32

标签: jquery jquery-ui jquery-ui-tabs

我需要根据特定条件停止标签更改的默认行为。我的问题是,一旦我在我的标签上发出.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>

0 个答案:

没有答案