Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery previous按钮需要在第一个问题上不可见。)1&;jquerynext按钮需要在最后一页不可见,即Q.)10_Javascript_Jquery_Html_Button - Fatal编程技术网

Javascript jQuery previous按钮需要在第一个问题上不可见。)1&;jquerynext按钮需要在最后一页不可见,即Q.)10

Javascript jQuery previous按钮需要在第一个问题上不可见。)1&;jquerynext按钮需要在最后一页不可见,即Q.)10,javascript,jquery,html,button,Javascript,Jquery,Html,Button,好的,我遇到了一个小问题,我有两个jQuery按钮“previous”和“Next”,现在我需要做的是在第一个问题上使previous按钮不可见,因为你不能后退,而在最后一页上使Next按钮不可见,因为这是最后一页。最好的办法是什么。这是我的代码 if (i.Question_Type == "DROPDOWN") { <div class="container text-center"> <div cla

好的,我遇到了一个小问题,我有两个jQuery按钮“previous”和“Next”,现在我需要做的是在第一个问题上使previous按钮不可见,因为你不能后退,而在最后一页上使Next按钮不可见,因为这是最后一页。最好的办法是什么。这是我的代码

     if (i.Question_Type == "DROPDOWN")
    {

        <div class="container text-center">


                <div class="row idrow" data-questions="@counter">
                    @{counter++;
                    }




                        <div id="question1" class="form-group">
                            <label class="lab text-center" for="form-group-select">
                                @i.Question_Order @Html.Raw(@i.Question)
                            </label>
                            <select class="form-control" id="form-group-select">
                                @for (int x = 1; x <= Convert.ToInt32(i.Question_SubType); x++)
                                    {
                                        var t = x - 1;
                                        if (i.qOps != null)
                                        {
                                        <option> @i.qOps.options[t]</option>
                                        }
                                        else
                                        {
                                        <option> @x</option>

                                        }
                                    }
                            </select>
                        </div>







                </div>

        </div>

                        }

                        if (i.Question_Type == "RADIO")
                        {




        <div class="container">
            <div class="row idrow" data-questions="@counter">
                @{counter++;
                }
                <div class="form-group">
                    <label class="lab" for="questions">
                       @i.Question_Order @i.Question
                    </label>
                    <div class="row">
                        <div class="col-xs-12">
                            <div id="question1" class="radio-inline">
                                @for (int x = 1; x <= Convert.ToInt32(i.Question_SubType); x++)
                                {
                                    var t = x - 1;
                                    if (i.qOps != null)
                                    {
                                        <label class="radio-inline"><input type="radio" name="question"> @i.qOps.options[t]</label>
                                    }
                                    else
                                    {

                                          <label class="radio-inline"><input type="radio" min="0" max="@x" name="question"></label>

                                    }
                                }
                            </div>

                        </div>

                    </div>
                </div>


            </div>
        </div>

    }
    if (i.Question_Type == "CHECKBOX")
    {
        for (int y = 1; y <= Convert.ToInt32(i.Question_SubType); y++)
        {
            @*<div class="container">
                <div class="row">

                    <label>@y</label>   <input type="checkbox" name="question">

                </div>
            </div>*@
        }
    }

}
<div class="azibsButtons">
    <button type="button" id="previous"  class="btn btn-primary pull-left">Prev</button>

    <button type="button" id="next"  class="btn btn-primary pull-right">Next</button>
</div>



<script>
    $(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;

                    }

                });
            });


    });

</script>
if(问题类型==“下拉列表”)
{
@{计数器++;
}
@i、 问题\顺序@Html.Raw(@i.Question)

@对于(intx=1;x您的代码应该是这样的..试试这个,如果您需要任何解释,请告诉我

$(document).ready(function () {
  ShowTheelement(0);                     //run a function 
  $("#previous").addClass('hidden');     // hide the previous button

  var dataVal = 0;                       // set dataVal to 0

  $("#next").click(function () {
    dataVal++;                           // add 1 to data val on each click
    $("#previous").removeClass('hidden');// show the previous button
    dataVal ==  $(".idrow[data-questions]").length - 1 ? $(this).addClass('hidden'): $(this).removeClass('hidden');  // similar to if/else statement .. If dataVal equal the numbers of `idrow` - 1 hide the next button if not show the next button
    ShowTheelement(dataVal);  // run a function to hide divs and show just the one we need with new `dataVal`
  });

    $("#previous").click(function () {
      dataVal--;
      $("#next").removeClass('hidden');
      dataVal ==  0 ? $(this).addClass('hidden'): $(this).removeClass('hidden');
      ShowTheelement(dataVal);
  });
});
// function to hide all `.idrow` elements and show the one with `data-questions='"+dataVal+"'`
function ShowTheelement(dataVal){
    $(".idrow").addClass('hidden');
    $(".idrow[data-questions='"+dataVal+"']").removeClass('hidden');
}
说明

  • 当您需要添加/删除类onload时,单击“下一步”按钮和“上一步”按钮。无需每次重复代码。最好为此创建一个函数,并将
    dataVal
    传递给此函数

  • 有关更多说明,请阅读代码上的注释


您对
的期望返回false;
要做什么?我不太了解jqurey,但我相信这没有什么区别。我认为没有必要使用
。每个()
next
上,甚至在
previous
上,您只需检查未隐藏的元素是否是第一个hide
prev
按钮,以及是否是最后一个hide
next
按钮。创建一个包含相关(html、css、js)代码的演示。每个()是否因为问题是链接的,所以有一个数据表,该表也有问题顺序,因此.each()loop正在修改订单,请共享HTML,以便更好地理解问题和流程。ShowTheelement代表什么?@FaizanHaque此函数用于隐藏所有
.idrow
元素,并仅显示包含您需要显示的
数据问题的元素。.我们需要在准备好文档和下一个cl时执行此操作单击ick并单击prev,这样我们就不用重复我们的代码了,我们可以为遇到问题的itOkay创建一个简单的函数。我把你的代码放进去了,很明显,它只显示下一个底部,上一个按钮不显示在下一个底部all@FaizanHaque对不起,我的不好。请稍等。同时也谢谢你的帮助