单击jQuery前一个按钮返回Q.)1而不是一个接一个地向后退

jQuery上一个按钮没有按预期工作。
基本上解释它的最好方法是,如果我在问题5并且我点击上一个按钮,它默认为问题1而不是问题4。

所以这是问题1的默认…这是一个问题。
该怎么办?

jQuery位于脚本标记的底部。

if (i.Question_Type == "DROPDOWN") { 
@{ counter++; }
@for (int x = 1; x <= Convert.ToInt32(i.Question_SubType); x++) { var t = x - 1; if (i.qOps != null) { @i.qOps.options[t] } else { @x } }
} if (i.Question_Type == "RADIO") {
@{counter++; }
@for (int x = 1; x <= Convert.ToInt32(i.Question_SubType); x++) { var t = x - 1; if (i.qOps != null) { } else { } }
} if (i.Question_Type == "CHECKBOX") { for (int y = 1; y <= Convert.ToInt32(i.Question_SubType); y++) { @*
*@ } } }
$(document).ready(function () { $(".idrow").each(function (i) { var inner = $(this).data('questions'); if (inner == 0) { $(this).removeClass('hidden'); } else { $(this).addClass('hidden'); } }); $("#next").click(function () { $(".idrow").each(function (i) { var inp = $(this); if (!inp.hasClass('hidden')) { var dataVal = inp.data("questions"); dataVal++; inp.addClass('hidden'); $('[data-questions=' + dataVal + ']').removeClass('hidden'); return false; } }); $("#previous").click(function () { $(".idrow").each(function (i) { var inp = $(this); if (!inp.hasClass('hidden')) { var dataVal = inp.data("questions"); dataVal--; inp.addClass('hidden'); $('[data-questions=' + dataVal + ']').removeClass('hidden'); return false; } }); }); }); });

嘿家伙我得到了解决方案感谢Daniel。

关闭括号的下一个事件是围绕上一个事件进行的,这导致问题在前一个单击时默认为问题1。

 $("#next").click(function () { $(".idrow").each(function (i) { var inp = $(this); if (!inp.hasClass('hidden')) { var dataVal = inp.data("questions"); dataVal++; inp.addClass('hidden'); $('[data-questions=' + dataVal + ']').removeClass('hidden'); return false; } }); }); $("#previous").click(function () { $(".idrow").each(function (i) { var inp = $(this); if (!inp.hasClass('hidden')) { var dataVal = inp.data("questions"); dataVal--; inp.addClass('hidden'); $('[data-questions=' + dataVal + ']').removeClass('hidden'); return false; } }); });