三生石@ 2018-08-08 08:06 采纳率: 100%
浏览 11

使用引导程序的模态弹出窗口

I am very new to html and javascript. I am trying to pop up a modal in my index.html file but when I am using href it is just going to a different page. When I write the modal.html in the index.html file it works completely fine. It pops up nicely with my css design but when I put it in a separate file it takes me to a different page. I will have a lot of modal in my index page if I keep them in the same index file. So it will be nice if I can put them in separate files.

this is my index.html

<div id="three"> <div class="certificate"> Certificate Programs</div>
           <div class="button" id="net" data-toggle="modal" data-target="myModal"> <a href='modal.html' class="myButton">Networking Tech</a></div>
            <div class="button"><a href="#" class="myButton">Information Security</a></div>
           <div class="button"><a href="#" class="myButton">Software Development</a></div>
           <div class="button"><a href="#" class="myButton"> Database Technology Certificate</a></div>         
</div>

this is my modal.html:

<div id="myModal" class="modal fade" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Network Technology Certificate</h4>
            </div>
            <div class="modal-body">
                <p>Need any three courses for this cetificate.</p>
                <ul>
                    <li>IT 360 Intro to Networking(4)</li>
                    <li>IT 460 Net& Sec Protocol (4)</li>
                    <li>IT 462 Net Administration and Progr (4)</li>
                    <li>IT 483 Web Application and User Inter (4)</li>
                </ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
  • 写回答

4条回答 默认 最新

  • weixin_33749242 2018-08-08 08:17
    关注

    You should add button or link like this:

    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"></button>
    

    Notice data-target="exampleModal", this should be id of your modal. In your case it is "myModal".

    This will always redirect you to the new page because it is link inside of the div and it doesn't know that it has to open modal:

    <div class="button" id="net" data-toggle="modal" data-target="myModal"> <a href='modal.html' class="myButton">Networking Tech</a></div>
    

    Try to change CSS, or set it something like this:

    <a href="#" class="button" data-toggle="modal" data-target="#exampleModal">Networking Tech</a>
    

    So at the end you would have something like this:

    <div id="three"> <div class="certificate"> Certificate Programs</div>
               <a href="#" class="button" data-toggle="modal" data-target="#exampleModal">Networking Tech</a>
                <div class="button"><a href="#" class="myButton">Information Security</a></div>
               <div class="button"><a href="#" class="myButton">Software Development</a></div>
               <div class="button"><a href="#" class="myButton"> Database Technology Certificate</a></div>         
    </div>
    

    I also recommend using of unordered list in this scenario.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程