1

我正在使用 MVC4/C# 开发一个移动网站,并正在使用向导进行一些数据输入 ( http://afana.me/post/create-wizard-in-aspnet-mvc-3.aspx ) 我是还使用 jQuery v1.8 和 jQuery mobile 1.3.1。

出于某种原因,当最初显示第 1 步时,我无法让“后退”按钮隐藏(),前进到第 2 步并返回第 1 步确实隐藏后退按钮,使用以下代码:

$("#back-step").closest('.ui-btn').hide();

当我在 $document.ready 中(或在设置事件处理程序之前)使用完全相同的代码时,它不会隐藏页面/步骤的初始视图上的按钮。

脚本代码是从一个单独的文件加载的,加载脚本代码发生在 cshtml 文件的底部。

<script src="~/Scripts/Custom/Wizard.js"></script>

我只是想知道我必须做些什么才能使它正常工作,我在这里搜索并尝试了各种方法,例如 $(#back-step").hide$ 几个小时,但我无法让它正常工作. 我在下面的代码中添加了一些“警报”,以查看代码是否“命中”并且确实如此,所以我无法理解为什么按钮没有隐藏。

希望这里有人可以提供帮助,我在下面包含了javascript。

这是向导的javascript代码:

$(function () {

$(".wizard-step:first").show();             // show first step

$("#back-step").closest('.ui-btn').hide();
alert('hide! first');

// attach nextStep button handler       
$("#next-step").click(function () {
    var $step = $(".wizard-step:visible"); // get current step

    var validator = $("form").validate(); // obtain validator
    var anyError = false;
    $step.find("input").each(function () {
        if (!validator.element(this)) { // validate every input element inside this step
            anyError = true;
        }

    });

    if (anyError)
        return false; // exit if any error found

    if ($step.next().hasClass("confirm")) { // is it confirmation?

        try {
            $("form").submit();
        }
        catch (e) {
            alert(e.name + ": " + e.message + " " + e.description);
        }
    }

    if ($step.next().hasClass("wizard-step")) { // is there any next step?
        $step.hide().next().fadeIn();  // show it and hide current step
        $("#back-step").closest('.ui-btn').show();
    }
    else { // this is last step, submit form
        $("form").submit();
    }
});


// attach backStep button handler
// hide on first step
$("#back-step").click(function () {
    var $step = $(".wizard-step:visible"); // get current step
    if ($step.prev().hasClass("wizard-step")) { // is there any previous step?
        $step.hide().prev().fadeIn();  // show it and hide current step

        // disable backstep button?
        if (!$step.prev().prev().hasClass("wizard-step")) { // $step.prev().prev() == $(".wizard-step:first")) {
            $("#back-step").closest('.ui-btn').hide();
        }
    }
    else {
        $("#back-step").closest('.ui-btn').hide();
    }
});
});

$(document).ready(function () {
    $("#back-step").closest('.ui-btn').hide();
    alert('hide! in ready');
});
4

0 回答 0