-1
爲什麼說 - '_'是未定義的,下面是一個基本的簡單例子和小提琴。謝謝爲什麼說 - 下劃線未定義
-------------index.html---------------------------
<html>
<head>
<title></title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="myJs.js"></script>
<head>
<html>
<body>
<script>
<button type="button" onclick = "loadThis();">Click Me!</button>
</script>
</body>
</html>
-------------myJs.js---------------------------
var loadThis = function(){
vas x = _.uniq([1, 2, 1, 3, 1, 4]);
alert(x);
};
JS Fiddle中的示例代碼不會給出與您在問題中描述的相同的錯誤。請提供一個準確反映您問題的示例。 – Quentin 2013-04-09 09:05:56
由於您選擇了在onLoad處理程序中加載JavaScript並將其定義爲本地變量的選項,因此您的小提琴找不到'loadThis'。如果你解決這個問題,它會按預期工作。明顯的懷疑是'underscore.js'沒有加載。所有現代瀏覽器都有工具來驗證。 – 2013-04-09 09:09:05
你確定'underscore.js'腳本是從你的頁面正確加載的嗎?檢查錯誤控制檯。 – Bergi 2013-04-09 09:17:56