weixin_33736649 2018-11-26 18:56 采纳率: 0%
浏览 126

如何显示/隐藏div Ajax Jquery?

我在这个问题上花了很多时间,我一直找不到.parent()、Next()、.Next()或.Next()。为此,我想在设置了.put-range滑块值后,在Ajax上成功显示出名为.SubQuestion的div。一切运行良好,但是在$(this).next(".SubQuestion").show();和$(this).next(".SubQuestion").hide();上却不起作用。

我找不到div类显示,CSS也不工作。

<div class="row">
    <div class="col-9 my-1 input-ranges" id="range">
        @{ var questionId = Model.QuestionAndAnswer[i].QuestionId;
            var AcceptableScore = Model.QuestionAndAnswer[i].QuestionAcceptableScore;
        }
        @Html.TextBoxFor(model => model.QuestionAndAnswer[i].Ans_Score, htmlAttributes: new { @id = questionId, @tag = AcceptableScore, @class = "input-range", @min = "1", @max = "10", @step = "1", @type = "range" })
        YourScore <span class="range-value">1</span>
    </div>

    <div class="col-3">
        <a data-toggle="collapse" href="#ScoreComment_@i" role="button" aria-expanded="false" aria-controls="collapseExample">
            <div class="fs-3x text-center text-info"><i class="la la-comment-o"></i></div>
        </a>
    </div>

    <div class="col-12 bg-info SubQuestion" style="display:none">
        <h1>Result</h1>
    </div>

    <div class="col-12">
        <div class="collapse my-1" id="ScoreComment_@i">
            @Html.TextAreaFor(model => model.QuestionAndAnswer[i].Ans_Score_Note, new { @class = "form-control p-1 w-100", @maxlength = "4000", @rows = "4", @placeholder = "توضیحات" })
        </div>
    </div>
</div>

<script>
      $(function ($) {
         console.log($.ajax);
         $('.input-range').on('change', function () {
             $(this).next('.range-value').html(this.value);

             var questionId = $(this).attr("id");
             var QAScore = $(this).attr("tag");
             var rangevalue = $(this).nextAll('.range-value').first().text();
             if (rangevalue < QAScore) {
                 $.ajax({
                     url: "/Question/GetSubQuestion",
                     type: "POST",
                     datatype: "json",
                     data: { QuestionId: questionId },
                     success: function (data) {
                         $(this).next(".SubQuestion").html(data);
                         $(this).next(".SubQuestion").show(); 
                     }
                 });
             }
             else {
                 $(this).parent().nextAll(".SubQuestion").hide();
             }
         });
     });

    </script>
  • 写回答

1条回答 默认 最新

  • 七度&光 2018-11-27 06:25
    关注

    Here was the solution Thanks to @AndrewLohr

    $(function ($) {
        $('.input-range').on('change', function () {
            $(this).next('.range-value').html(this.value);
            let subQuestion = $(this).parent().nextAll(".SubQuestion").show();
            var questionId = $(this).attr("id");
            var QAScore = $(this).attr("tag");
            var rangevalue = $(this).nextAll('.range-value').first().text();
            if (rangevalue < QAScore && rangevalue!=10) {
                $.ajax({
                    url: "/Question/GetSubQuestion",
                    type: "POST",
                    datatype: "json",
                    data: { QuestionId: questionId },
                    success: function (data) {
                        subQuestion.html(data);
                        subQuestion.show();
                    }
                });
            }
            else {
                $(this).parent().nextAll(".SubQuestion").hide();
            }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题