Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:$(…)。模式不是函数_Javascript_Jquery_Bootstrap Modal - Fatal编程技术网

Javascript TypeError:$(…)。模式不是函数

Javascript TypeError:$(…)。模式不是函数,javascript,jquery,bootstrap-modal,Javascript,Jquery,Bootstrap Modal,我试图在单击HTML标记时获得模式加载,如下所示: <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script> <script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script> <script src

我试图在单击HTML标记时获得模式加载,如下所示:

<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div>
    <table class="usersTables" id="userTable">
        <thead>
            <tr>
                <th scope="col"><?= $this->Paginator->sort('name') ?></th>
                <th scope="col" class="actions"><?= __('Actions') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($users as $user): ?>
            <tr>
                <td><?= h($user->name) ?></td>                  
                <td class="actions">
                    <a href="#" id="managephoto">Manage Photo</a>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>

<script type="text/javascript">
    $(function () {
         $('#managephoto').click(function () {
              $('#myModal').modal('show');
         });
    });
</script>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                 </button>
                 <h4 class="modal-title" id="myModalLabel">Photo</h4>
            </div>
            <div class="modal-footer">
                 <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                 <button id="savebutton" type="button" class="btn btn-primary" data-dismiss="modal">Save changes</button>
            </div>
        </div>
    </div>
</div>
此错误仅出现在表中的第一个条目上,其他数据条目的所有其他相同链接均未显示此错误(我认为其他链接根本不起作用,因为它们也应给出相同的错误)

我也被直接发送到顶部,尽管我认为这是预期的,因为HTML标记有
href=“#”

我尝试了以下方法:

  • $(函数(){
    替换为
    $(文档)。就绪(函数(){
  • $(函数(){
    替换为
    $(窗口)。加载(函数(){

$('document').ready(函数(){
$('#managephoto')。单击(函数(){
$('myModal').modal('show');
});
});

试试看,它会起作用。

确保只包含一个jQueryAlso副本。因此,您可能会使用
id=“managephoto”创建多个元素
如您所见,它对第一个链接正常工作。后者不是由于ID重复,但也不会触发您看到的错误。我怀疑您包含了第二个jQuery实例,它重置了可用插件,删除了
jQuery.fn.modal
谢谢,这很有帮助(我确实又找到了一个我错过的jQuery脚本)现在,它允许第一个链接加载模式。在另一个问题中,我想将PHP变量传递给一个模式,以便根据我单击的链接,它将传递相应的ID。例如,我单击第一个链接,我将管理ID=1的用户的照片,第二个链接将引导我管理ID=2的用户的照片,依此类推。答案是该问题中的ot是使用数据id,尽管答案不完整:如果您还有其他问题,与上述问题无关,请将其作为新问题发布
Uncaught TypeError: $(...).modal is not a function
 <script type="text/javascript">
  $('document').ready(function () {
    $('#managephoto').click(function () {
            $('#myModal').modal('show');
    });
  });
</script>