我在jquery.steps.js库中遇到了函数:
/**
* Routes to a specific step by a given index.
*
* @static
* @private
* @method goToStep
* @param wizard {Object} The jQuery wizard object
* @param options {Object} Settings of the current wizard
* @param state {Object} The state container of the current wizard
* @param index {Integer} The position (zero-based) to route to
* @return {Boolean} Indicates whether the action succeeded or failed
**/
function goToStep(wizard, options, state, index)
{
if (index < 0 || index >= state.stepCount)
{
throwError(_indexOutOfRangeErrorMessage);
}
if (options.forceMoveForward && index < state.currentIndex)
{
return;
}
var oldIndex = state.currentIndex;
if (wizard.triggerHandler("stepChanging", [state.currentIndex, index]))
{
// Save new state
state.currentIndex = index;
saveCurrentStateToCookie(wizard, options, state);
// Change visualisation
refreshStepNavigation(wizard, options, state, oldIndex);
refreshPagination(wizard, options, state);
loadAsyncContent(wizard, options, state);
startTransitionEffect(wizard, options, state, index, oldIndex);
wizard.triggerHandler("stepChanged", [index, oldIndex]);
}
else
{
wizard.find(".steps li").eq(oldIndex).addClass("error");
}
return true;
}我想使用这个函数,所以每次用户在wizzard中在step 3上提交表单时,他将不再被重定向到step 1,而是停留在step 3。
贝娄是我的剧本:
$("#wizard-2").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
onStepChanging: function (event, currentIndex, newIndex)
{
$("#form-2").validate().settings.ignore = ":disabled,:hidden";
return $("#form-2").valid();
},
onFinishing: function (event, currentIndex)
{
$("#form-2").validate().settings.ignore = ":disabled";
return $("#form-2").valid();
},
onFinished: function (event, currentIndex)
{
$('<input />').attr('type', 'hidden')
.attr('name','ssl')
.attr('value', 'true')
.appendTo('#form-2');
document.getElementById("form-2").submit();
}
});
<? if ($_POST['submit'])
echo "$(\"wizard-2\").goToStep(this, ,3,0);"?>但是我认为我执行这个函数很糟糕,因为它不起作用。有人能帮我写这个剧本吗?
发布于 2014-02-10 13:30:41
我自己想出来的。问题很容易解决,问题是如何正确设置属性startIndex,例如:
<?
if (Env::value('generate'))
echo "startIndex: \"2\",";
?> https://stackoverflow.com/questions/21672750
复制相似问题