Javascript “提交答案”按钮不转到下一步(字段集),但单击“下一步”按钮会转到下一步

Javascript “提交答案”按钮不转到下一步(字段集),但单击“下一步”按钮会转到下一步,javascript,html,jquery,angularjs,Javascript,Html,Jquery,Angularjs,我有简单的多种形式的标签。它工作正常,当我单击每个字段集内的“下一步”按钮时,它将导航到下一个字段集。它工作得很好,但我在第一个字段集中创建了一个新按钮“提交答案”,它将调用Angularjs函数,在成功块中完成提交答案后,我尝试使用导航到下一个字段集的下一个按钮的相同逻辑。这在提交答案的成功块内不起作用。我有什么遗漏吗?第一个字段集中的“外部下一步”按钮非常有效 <!-- fieldsets --> <fieldset> <

我有简单的多种形式的标签。它工作正常,当我单击每个字段集内的“下一步”按钮时,它将导航到下一个字段集。它工作得很好,但我在第一个字段集中创建了一个新按钮“提交答案”,它将调用Angularjs函数,在成功块中完成提交答案后,我尝试使用导航到下一个字段集的下一个按钮的相同逻辑。这在提交答案的成功块内不起作用。我有什么遗漏吗?第一个字段集中的“外部下一步”按钮非常有效

<!-- fieldsets -->
        <fieldset>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group text-center">
                        <strong>Test</strong>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="form-group text-center">
                        <input type="text" class="form-control" id="txt-Answer" name="txt-Answer" maxlength="100" ng-model="testAnswer" style="width:120%;" />
                    </div>
                </div>
                <br />
                <div class="row">
                    <div class="col-md-12 text-center">
                        <input type="button" name="btnSubmitAnswer" class="next action-button" value="Submit Answer" ng-click="submitAnswer(userInfo.UserSecurityQuestion[0].SecurityQuestionId);" />
                    </div>
                </div>
            </div>
            <input type="button" name="next" class="next action-button" value="Next" />
        </fieldset>
        <fieldset>
            <h2 class="fs-title">Test</h2>
            <h3 class="fs-subtitle">Test</h3>
            @*<input type="text" name="twitter" placeholder="Twitter" />
        <input type="text" name="facebook" placeholder="Facebook" />
        <input type="text" name="gplus" placeholder="Google Plus" />*@
            @*<input type="button" name="previous" class="previous action-button" value="Previous" />
        <input type="button" name="next" class="next action-button" value="Next" />*@
            <input type="submit" name="submit" class="submit action-button" value="Submit" />
        </fieldset>
        @*<fieldset>
            <h2 class="fs-title">Test</h2>
            <h3 class="fs-subtitle">We will never sell it</h3>
            <input type="text" name="fname" placeholder="First Name" />
            <input type="text" name="lname" placeholder="Last Name" />
            <input type="text" name="phone" placeholder="Phone" />
            <textarea name="address" placeholder="Address"></textarea>
            <input type="button" name="previous" class="previous action-button" value="Previous" />
            <input type="submit" name="submit" class="submit action-button" value="Submit" />
        </fieldset>*@
单击提交答案按钮-这不起作用(不进入步骤2(字段集)


您必须在函数中使用
,该函数不引用任何元素。这就是为什么函数中没有任何元素。相反,您可以使用
进度条
获取类
处于活动状态的
li
的索引。单击
后,下一步
按钮将添加活动cl见鬼去吧

然后,使用该
索引
获取位于该位置的
字段集
(“字段集:eq(“+next_fs+”))
这将为您提供需要隐藏的字段集的引用。您也可以对下一步需要显示的另一个
字段集
执行相同的操作

演示代码(在下面的代码中,我没有使用angularjs,而是简单地使用click事件,并从那里调用了nextFieldSet):

$(“字段集:第一个”).fadeIn();//显示第一个字段集
var动画;
$(“.next”)。单击(函数(){
如果(动画)返回false;
动画=真;
当前_fs=$(this.parent();
next_fs=$(this.parent().next();
//移除当前激活的
$(“#progressbar li”).eq($(“字段集”).index(当前的#fs)).removeClass(“活动的”)
$(“#progressbar li”).eq($(“字段集”).index(next_fs)).addClass(“活动”);
next_fs.show();
//使用样式隐藏当前字段集
当前动画({
不透明度:0
}, {
步骤:函数(现在是mx){
比例=1-(1-现在)*0.2;
左=(现在是*50)+“%”;
不透明度=1-现在;
当前_fs.css({
“转换”:“缩放(“+scale+”),
“位置”:“绝对”
});
next_fs.css({
"左":左,,
“不透明度”:不透明度
});
},
持续时间:800,
完成:函数(){
当前_fs.hide();
动画=假;
},
//这来自自定义的放松插件
放松:“轻松返回”
});
});
//假设提交按钮是单击
$(“.action按钮”)。单击(函数(){
//调用函数
nextFieldSet()
})
函数nextFieldSet(){
如果(动画)返回false;
动画=真;
//获取活动li索引
当前_fs=$(“#progressbar li.active”).index();
//对于下一个div,添加1
next_fs=$(“#progressbar li.active”).index()+1;
$(“#progressbar li”).eq(当前的_fs).removeClass(“活动的”)//删除当前活动的
//使用next_fs的索引在progressbar上激活下一步
$(“#progressbar li”).eq(next_fs).addClass(“活动”);
var next\u divs=$(“字段集:eq(“+next\u fs+”)//查找字段集eq
var current\u div=$(“字段集:eq(“+current\u fs+”))
//显示下一个字段集
下一个divs.show();
//使用样式隐藏当前字段集
当前分区动画({
不透明度:0
}, {
步骤:函数(现在是mx){
比例=1-(1-现在)*0.2;
左=(现在是*50)+“%”;
不透明度=1-现在;
当前_div.css({
“转换”:“缩放(“+scale+”),
“位置”:“绝对”
});
下一个divs.css({
"左":左,,
“不透明度”:不透明度
});
},
持续时间:800,
完成:函数(){
当前分区隐藏();
动画=假;
},
放松:“轻松返回”
});
}
字段集{
显示:无;
}
.主动{
颜色:红色;
}

  • 1
  • 2
  • 3
测试
试验 试验 试验 我们永远不会卖掉它
你能把它当作一个工作片段吗?这与Parent.Next()有关吗
$(".next").click(function () {
            if (animating) return false;
            animating = true;

            current_fs = $(this).parent();
            next_fs = $(this).parent().next();

            //activate next step on progressbar using the index of next_fs
            $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

            //show the next fieldset
            next_fs.show();
            //hide the current fieldset with style
            current_fs.animate({ opacity: 0 }, {
                step: function (now, mx) {
                    //as the opacity of current_fs reduces to 0 - stored in "now"
                    //1. scale current_fs down to 80%
                    scale = 1 - (1 - now) * 0.2;
                    //2. bring next_fs from the right(50%)
                    left = (now * 50) + "%";
                    //3. increase opacity of next_fs to 1 as it moves in
                    opacity = 1 - now;
                    current_fs.css({
                        'transform': 'scale(' + scale + ')',
                        'position': 'absolute'
                    });
                    next_fs.css({ 'left': left, 'opacity': opacity });
                },
                duration: 800,
                complete: function () {
                    current_fs.hide();
                    animating = false;
                },
                //this comes from the custom easing plugin
                easing: 'easeInOutBack'
            });
        });
$scope.submitAnswer = function ()
        {
                $http({
                    method: 'POST',
                    url: window.location.protocol + '//' + window.location.host + '/Home/SubmitAnswer'
                }).then(
                    function (response) {
                        //Response Message
                        if (response.data.isMatchedResult)
                        {
                            nextFieldSet();
                            
                        }
                    }
                );
            }
        }
        
        function nextFieldSet()
        {
            if (animating) return false;
            animating = true;

            current_fs = $(this).parent();
            next_fs = $(this).parent().next();

            //activate next step on progressbar using the index of next_fs
            $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

            //show the next fieldset
            next_fs.show();
            //hide the current fieldset with style
            current_fs.animate({ opacity: 0 }, {
                step: function (now, mx) {
                    //as the opacity of current_fs reduces to 0 - stored in "now"
                    //1. scale current_fs down to 80%
                    scale = 1 - (1 - now) * 0.2;
                    //2. bring next_fs from the right(50%)
                    left = (now * 50) + "%";
                    //3. increase opacity of next_fs to 1 as it moves in
                    opacity = 1 - now;
                    current_fs.css({
                        'transform': 'scale(' + scale + ')',
                        'position': 'absolute'
                    });
                    next_fs.css({ 'left': left, 'opacity': opacity });
                },
                duration: 800,
                complete: function () {
                    current_fs.hide();
                    animating = false;
                },
                //this comes from the custom easing plugin
                easing: 'easeInOutBack'
            });
        }