doudizhi947129 2018-12-11 13:27
浏览 114
已采纳

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

I can open my modal with script (id matches), but function on show does not get triggered. I just want to find out why can't I trigger that function? Is my js syntax wrong? Should I have it all in "document ready" function?.

MAIN

 <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>
  • 写回答

1条回答 默认 最新

  • dsklzerpx64815631 2018-12-11 13:31
    关注

    The event is called show.bs.modal not shown.bs.modal

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

    Bootstrap provides custom events for most plugins' unique actions. Generally, these come in an infinitive and past participle form - where the infinitive (ex. show) is triggered at the start of an event, and its past participle form (ex. shown) is triggered on the completion of an action.

    As of 3.0.0, all Bootstrap events are namespaced.

    All infinitive events provide preventDefault functionality. This provides the ability to stop the execution of an action before it starts.

    $('#myModal').on('show.bs.modal', function (e) {   if (!data) return
    e.preventDefault() // stops modal from being shown })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题