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 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?