问题描述
<!-- 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吗?
解决方法
使用默认的javascript模态方法。 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();
})
}
});
');
如果不想显示保存和取消按钮,请删除此行,并使用页脚属性添加特定按钮。