从<a> Also .Show() might not be working

时间:2016-11-29 08:01:53

标签: javascript jquery html5 modal-dialog bootstrap-modal

I am fairly new to web development. I have this problem.. It is probably something simple but I can't seem to work it out.

I solved how to use a link to run some javascript. The javascript is supposed to open a modal but the script doesn't work.

To call my script I am using this: (I confirmed this works because I had placed an 'alert()' in the script to test if it went through)

<li>
    <a data-toggle="modal" href="javascript:void(0)" onclick="showBugForm()">
        <i class="fa fa-fw fa-bug"></i> Report a Bug
    </a>
</li>

The script being called is:

function showBugForm(){
    $('#repBug').modal('show');}

The main structure of my modal is shown below. I know the modal doesn't have any problems since I was able to load modal from a button, but I can't seem do it properly from an element. For the sake of context: I was able to load the modal by adding 'data-toggle="modal" data-target="#repBug"' to my button attributes, but I can't do the same with html link tag.)

<div class="modal fade" id="repBug" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
                   <!-- Here's my Code -->
        <div>
    <div>
<div>

Any clues?

2 个答案:

答案 0 :(得分:0)

<a data-target="#repBug" data-toggle="modal" href="#repBug"><i class="fa fa-fw fa-bug"></i> Report a Bug</a>

试试这个,它会解决你的问题。这里不需要调用任何函数。点击此锚标签后,您的模态将直接打开。

答案 1 :(得分:0)

我遇到的问题是因为我错过了补充:

<?php include_once('bug-form.php'); ?>

到我的index.php文件..因为我的代码是用不同的php文件编写的,名为&#39; bug-form。