我怎样可以在HTML文件内不触发事件而直接调用JavaScript函数?我想要像这样的代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="jquery.flot.js"></script>
<script src="chart.js"></script>
<title>
</title>
</head>
<body>
<div id="chart1" style="width:600px;height:300px"></div>
show_graph({{ chart_type }}, {{ data }}, {{ options }});
</body>
</html>
但这只会将函数调用打印到屏幕上,而不是实际执行该函数。
例如,我得到的结果是 show_graph(bar, [[1, 2000], [2, 50], [3, 400], [4, 200], [5, 5000]], ['Foo']);
我该怎么做呢?
编辑:
感谢反馈,但我尝试将其包装在 script 标签中,并收到“参数数量无效”的错误。
JavaScript 代码如下:
function show_graph(charttype, data, options){
var chart_options = {
series: {
charttype: {
show: true
}
}
}
var plot = $.plot($("#chart1"), [data], [chart_options]);
}
所以我想真正的问题是,“当我传递了三个参数并接受了三个参数时,为什么会出现“无效数量的参数”错误?”