Bootstrap Modal immediately disappearing

后端 未结 27 1142
清歌不尽
清歌不尽 2020-12-04 07:18

I\'m working on a website using bootstrap.

Basically, I wanted to use a modal in the home page, summoned by the button in the Hero Unit.

Button code:

27条回答
  •  生来不讨喜
    2020-12-04 07:25

    A Likely Cause

    This is typical behavior for when the JavaScript for the Modal plugin gets loaded twice. Please check to make sure that the plugin isn't getting double loaded. Depending on the platform you are using, the modal code could be loaded from a number a sources. Some of the common ones are:

    • bootstrap.js (the full BootStrap JS suite)
    • bootstrap.min.js (same as above, just minified)
    • bootstrap-modal.js (the standalone plugin)
    • a dependency loader, e.g., require('bootstrap')

    Debugging Tips

    A good place to start is to inspect the registered click event listeners using the developer tools in your browser. Chrome, for instance, will list the JS source file where the code to register the listener can be found. Another option is to try searching the sources on the page for a phrase found in the Modal code, e.g., var Modal.

    Unfortunately, these won't always find things in all cases. Inspecting the network requests can be a little more robust at giving you a picture of everything loaded on a page.

    A (Broken) Demo

    Here's a demo of what happens when you load both the bootstrap.js and bootstrap-modal.js (just to confirm your experience):

    Plunker

    If you scroll down to the bottom of the source on that page, you can remove or comment out the

提交回复
热议问题