Bootstrap Modal onmouseover

时间:2015-02-03 06:08:49

标签: javascript php twitter-bootstrap

所以我正在处理我的个人网页,这是我第一次使用Bootstrap进行开发。我使用php,html,css和JS作为我的开发堆栈。我遇到的错误是尝试创建一个元素: 1.如果php测试通过,创建一个div,并在JS中附加onemouseover事件(我知道如何做这件事) 2.我想要一个bootstrap模式打开并转换onmouseoever,并关闭,onmouseleave。 这是到目前为止的代码,createModal函数是空的,因为使用this.innerHTML = blahblahblah不起作用。

        <?php 
        if(!isset($_GET["nfc"])){
            $nfc = false;
        } else {
            $nfc = filter_var($_GET["nfc"], FILTER_VALIDATE_BOOLEAN);
        }
    ?>

<?php 
        if ($nfc == true) { ?>
            <a href="#"
            id="nfc"
            data-toggle="modal"
            data-target="#basicModal"><i class="fa fa-chevron-circle-down fa-5x"></i></a>
            <div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button>
                        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                        </div>
                        <div class="modal-body">
                            <h3>Modal Body</h3>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary">Save changes</button>
                        </div>
                    </div>
                </div>
            </div>
        <?php } else { ?>
            <i class="fa fa-chevron-circle-down fa-5x"></i>
        <?php } ?>
    </div>

JS:     var element = document.getElementById(“nfc”);         if(typeof(element)!='undefined'&amp;&amp; element!= null){             element.onmouseover = createModal;         }

1 个答案:

答案 0 :(得分:0)

您可以使用以下jquery代码隐藏您的模态

$(document).ready(function(e){
  $("body").find("#nfc").hover(function() {
      $("#basicModal").modal('show');
  }, function(){
      $("#basicModal").modal('hide');                            
  });
});