【问题标题】:Moodle quiz display modal only during attempt not during reviewMoodle 测验仅在尝试期间而不是在复习期间显示模式
【发布时间】:2020-08-21 08:22:22
【问题描述】:

我使用下面的代码在 moodle quiz 的问题上添加了一个模态表单:

<!-- Modal -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">

    <div class="modal-dialog">

        <div class="modal-content">

            <div class="modal-header">

                <h4 class="modal-title" id="myModalLabel"></h4>

            </div>

            <div class="modal-body">

                <h4>The time allocated for this question is over. Please go to the next page: </h4>

            </div>

            <div class="modal-footer">

                <input type="submit" name="next" value="Next page" class="mod_quiz-next-nav btn btn-primary">

            </div>

        </div>

        <!-- /.modal-content -->

    </div>

    <!-- /.modal-dialog -->

</div>

<!-- /.modal -->

我想让这个模式仅在尝试期间而不是在审查期间可见。有什么办法可以用javascript来实现吗?

【问题讨论】:

    标签: jquery moodle jscript


    【解决方案1】:

    使用moodle 默认的javascript modal 方法。 https://docs.moodle.org/dev/AMD_Modal

    // Add your modal body content on footer mustache or theme incourse layout file.
      <div id="question-attepmt-popup" class="modal-content" style="display:none">
          <h4>The time allocated for this question is over. Please go to the next page: </h4>
      </div>
    
      // Place this code on your theme incourse layout file or yourtheme_page_init function. 
        global $PAGE;
        $PAGE->requires->js_amd_inline('
            require(["jquery", "core/modal_factory"], function($, ModalFactory){
                if ( $("body").attr("id") == "page-mod-quiz-attempt" ) {
                    ModalFactory.create({
                        type: ModalFactory.types.SAVE_CANCEL, 
                        title: "Delete item", // Your modal title.
                        body: $("#question-attempt-popup"),
                    }).then(function(modal) {
                        modal.show();
                    })
                }     
            });
        ');
    

    如果您不想显示保存和取消按钮,请删除此行并使用 footer 属性添加您的特定按钮。

    【讨论】:

      猜你喜欢
      • 2021-07-24
      • 1970-01-01
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多