我有這個代碼,讓我堅持了幾天我不明白爲什麼在我的控制檯說我的函數沒有定義這裏的代碼。順便說一句,我是超新的jQuery我真的沒有太多的知識,所以任何幫助?有人可以告訴我在哪裏出了錯,它的給我這個錯誤Jquery ReferenceError:(函數名稱)沒有定義
(ReferenceError: createGraph is not defined)
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="bin/js/raphael.js"></script>
<script src="bin/js/popup.js"></script>
<script src="bin/js/analytics.js"></script>
</head>
<body>
<div class="action-button">
<button id="1" value="1074">Button 1</button>
<button id="2" value="1074">Button 2</button>
</div>
<div id="output"></div>
<script>
/////////////////////////////////////////////////////
// this script will check if the document is ready and will display data for button 1
$(document).ready(function() {
$("#1").trigger("click");
});
///////////////////////////////////////////////////////////////////////////////////////
$("button").click(function() {
var attr = $(this).attr("id");
var val = $(this).val();
$.ajax({
type: "POST",
url: "bin/some.php",
data: { lookbookID: val, type:attr }
}).done(function(html) {
$("#output").html(attr + ' - ' + val + ' - ' + html);
createGraph();
});
});
</script>
</body>
</html>
和JS代碼
window.onload = function() {
function getAnchors(p1x, p1y, p2x, p2y, p3x, p3y) {
var l1 = (p2x - p1x)/2,
l2 = (p3x - p2x)/2,
a = Math.atan((p2x - p1x)/Math.abs(p2y - p1y)),
b = Math.atan((p3x - p2x)/Math.abs(p2y - p3y));
a = p1y < p2y ? Math.PI - a : a;
b = p3y < p2y ? Math.PI - b : b;
var alpha = Math.PI/2 - ((a + b) % (Math.PI * 2))/2,
dx1 = l1 * Math.sin(alpha + a),
dy1 = l1 * Math.cos(alpha + a),
dx2 = l2 * Math.sin(alpha + b),
dy2 = l2 * Math.cos(alpha + b);
return {
x1: p2x - dx1,
y1: p2y + dy1,
x2: p2x + dx2,
y2: p2y + dy2
};
}
function createGraph() {
// Grab the data
alert("i made it!");
var labels = [],
data = [];
$("#data tfoot th").each(function() {
labels.push($(this).html());
});
$("#data tbody td").each(function() {
data.push($(this).html());
});
}
};
我更新了這個遺憾我排除window.onload
我仍然得到的是引用錯誤,但如果我把這個函數放在window.onload = function
之外,那麼我的函數就可以工作了,有什麼方法可以訪問我的函數?我不知道如果我從windows.onload
刪除該程序代碼,我需要再次幫助:)
以防萬一的鏈接功能,這將是有幫助https://github.com/ksylvest/raphael-analytics
這不是如何定義功能。你需要學習基本的Javascript語法。 – SLaks 2013-05-10 17:06:56
'$(function createGraph()(){'是一個非常明顯的語法錯誤 – meagar 2013-05-10 17:07:03
+1只是修復了錯字錯誤 – SaidbakR 2013-05-10 17:08:22