引导功能“模态显示”未被触发

问题描述 投票:1回答:1

我可以用脚本(id匹配)打开我的模态,但show上的函数不会被触发。我只是想知道为什么我不能触发这个功能?我的js语法错了吗?我应该在“文件准备”功能中拥有它吗?

主要

 <body>
<?php

    require 'connect.php';

    $r = $db->getReference('guests');
    $ref = $r->getChild($dat)->getChild($id);
    $value = $ref->getValue();
    $json = json_encode($value);

    require 'model.html';
?>
</body>

<script>
    $(document).ready(function(){

    $('#modalas').modal('show');

    var obj = JSON.parse('<?= $json; ?>');
    console.log(obj);
    var vardass = obj.vardas;

    $("#modalas").on("shown.bs.modal", function () {
    console.log(vardass)
    var modal = $(this)
    $("#post_form")[0].reset();
    modal.find('.modal-title').text(vardass)

        document.getElementById("NameInput").value = obj.vardas;
        document.getElementById("LastInput").value = obj.pavarde;
    })
})
</script>
javascript php function bootstrap-modal
1个回答
0
投票

该事件被称为show.bs.modal而不是shown.bs.modal

来自https://getbootstrap.com/docs/3.3/javascript/#js-events

Bootstrap为大多数插件的独特操作提供自定义事件。通常,它们以不定式和过去的分词形式出现 - 在事件开始时触发不定式(例如show),并且在动作完成时触发其过去的分词形式(例如显示)。

从3.0.0开始,所有Bootstrap事件都是命名空间。

所有不定式事件都提供preventDefault功能。这提供了在动作开始之前停止执行的能力。

$('#myModal').on('show.bs.modal', function (e) {   if (!data) return
e.preventDefault() // stops modal from being shown })
© www.soinside.com 2019 - 2024. All rights reserved.