我在我的HTML文件的末尾調用了這個函數 - 它基本上只是一些我在網上找到的教程中的一些花哨的菜單。由於某種原因,JavaScript(包含在下面)永遠不會被調用。我甚至試圖添加一個alert()
來確認這一點,我從來沒有看到警報彈出,所以我知道它沒有被調用,但該文件確實存在於我的服務器上的那個位置。JS文件未加載
有什麼想法?
<script type="text/javasvcript" src="js/filestorage.js" />
filestorage.js
/**
* On DOMReady initialize page functionality
*/
$(document).ready(function(){
// Test we load this file
alert("READY!");
//Add functionality into the menu buttons
prepareMenu();
});
/**
* Prepares the menu buttons for selecting
* filetypes
* @return NULL
*/
function prepareMenu()
{
$("#menu li").click(
function() {
$("#menu li").each(
function(){
$(this).removeClass("active");
}
);
$(this).addClass("active");
HideFiles($(this).children().html());
return false;
});
//Select the first as default
$("#menu li:first").click();
}
/**
* Shows only the selected filetypes
* @param selector
* @return bool
*/
function HideFiles(selector)
{
//show all files
if(selector === "All files")
{
$("#files > li").show();
return true;
}
else
{
//show only the selected filetype
$("#files > li").hide();
$("#files > li." + selector).show();
return true;
}
}
有一些關於困惑自我關閉腳本標記。我會建議不要使用它們。總是你一個單獨的結束標籤。你可以在這裏找到更多的信息:http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work – Alex