我有這樣的代碼:https://jsfiddle.net/g412rft4/1/,你可以看到完美的作品。Jquery沒有正確加載
但是我試圖複製它與我的桌面上的test.html文件和Common.js文件以及它不起作用。看起來Jquery從未加載過,我不明白爲什麼。
這是.js文件的代碼:
$("#SaeReplacerBuilder").click(function() {
alert("ok");
});
這是.html文件的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Whatever</title>
<script src="//code.jquery.com/jquery-2.1.4.js"></script>
<script src="Common.js"></script>
</head>
<body>
<div id="SaeReplacerBuilder" style="background-color:#A0A0AA;border-radius:15px;padding-right:7px;padding-left:7px;border:2px solid #FF0000;color:#000000;">'''CLICK Here'''</div>
</body>
</html>
你可以從這裏加載jquery:'https:// ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'。這是來自Google API的最新版本。另外,如果你沒有在網站上這樣做,也就是說,你正在計算機上使用文件,如果你不在線,jquery將無法加載。 – TricksfortheWeb
將代碼包裝在'$(function(){/ * code here * /})'中。這對於所有jQuery來說都很基本。你的代碼在elememts存在之前運行 – charlietfl
現在它工作。謝謝你們倆。 – Saelyth