如何解决外部Javascript库无法正常工作的问题?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (88)

以下是我使用的代码:

<?php
include "connect.php";
session_start();
header('Content-Type: text/html; charset=utf-8');
?>
<head>
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.min.js"></script>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="style.css">

<script>
$(document).on('click', '[data-toggle="lightbox"]', function(event) {
                event.preventDefault();
                $(this).ekkoLightbox();
                    lightbox.option({
      'resizeDuration': 200,
      'albumLabel': "Image %1 of %2"
    })
            });

function goBack() {
    window.history.back()
}
function goNext() {
    window.location.href='index.php'
}
</script>
</head>

Ozel.js

$("#gonderelim").click(function(){
    $("#rating").hide();
    $.ajax({ 
        type:"post",
        url:"voting.php",
        data:$("#voting").serialize(),
        success:function(cevap) {
            $("b").text(cevap);
        }
    })
    $("#stats").load("stats.php");
})
提问于
用户回答回答于

在你的情况下,由于已经在使用jQuery,只需在ozel.js代码周围添加它

$( document ).ready(function() {
    // your code here
});

扫码关注云+社区

领取腾讯云代金券