以下是一個簡單的代碼,它顯示一個超鏈接並點擊它,一個警告框應該是可見的。但我沒看到它。這可能是什麼原因呢?我懷疑腳本本身沒有被調用。我哪裏錯了?爲什麼事件監聽器沒有被調用?
HTML:
<html>
<head>
<title></title>
</head>
<body>
<a href='#' id='sign-up-link'>Sign up</a>
<!-- scripts -->
<script href='jquery-2.1.1.js'></script>
<script href='script.js'></script>
</body>
的script.js:
$(document).ready(function() {
alert('Into the ready function');
$('#sign-up-link').click(function(event) {
event.preventDefault();
alert('Hey !!');
/*$('#sign-up-pop-up').style('display','block');
$('#sign-up-pop-up').style('top','500px');
$('$sign-up-pop-up').addClass('animated zoomIn');*/
});
});
您的「進入就緒功能」警報顯示在page_load上嗎? – 2014-09-26 17:42:47
代碼運行得很好,因爲您可以在此代碼的此jsfiddle版本中看到:http://jsfiddle.net/dp9qyfn4/,因此可能是您的頁面上有其他錯誤。 – radiovisual 2014-09-26 17:43:06
檢查您的控制檯日誌中的JavaScript錯誤。如果你的jQuery腳本路徑錯誤,'$'會產生一個錯誤,因爲$是一個jQuery別名。 – 2014-09-26 17:44:10