未捕获的ReferenceError:未定义myFunction [英] Uncaught ReferenceError: myFunction is not defined
本文介绍了未捕获的ReferenceError:未定义myFunction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出错误。我已将代码放在< / body>
之前。仍然出现错误。
Gives an error. I have placed the code just before </body>
. Still getting the error.
<form action="" method="get" id="searchform" >
<input name="q" type="text" id="search" size="32" maxlength="128" class="txt">
<input type="button" id="hit" value="Search" onclick="myFunction();return false" class="btn">
</form>
JS,
<script type="text/javascript">
var nexturl = "";
var lastid = "";
var param;
$(document).ready(function () {
function myFunction() {
param = $('#search').val();
alert("I am an alert box!");
if (param != "") {
$("#status").show();
var u = 'https://graph.facebook.com/search/?callback=&limit=100&q=' + param;
getResults(u);
}
}
$("#more").click(function () {
$("#status").show();
$("#more").hide();
pageTracker._trackPageview('/?q=/more');
var u = nexturl;
getResults(u);
});
});
</script>
推荐答案
你不能放置 myFunction
在 onclick
之后。当看到 onclick
时,没有 myFunction
的定义。
You cannot place myFunction
after the onclick
. When the onclick
is seen there is no definition for myFunction
.
将JavaScript放在< head>
标记中。另外,将功能移到 ready()
之外。
Place the JavaScript in <head>
tag. Also, move the function outside of ready()
.
像这样:
<script type="text/javascript">
var nexturl ="";
var lastid ="";
var param;
function myFunction() {
param = $('#search').val();
alert("I am an alert box!");
if (param != "") {
$("#status").show();
var u = 'https://graph.facebook.com/search/?callback=&limit=100&q='+param;
getResults(u);
}
}
$(document).ready(function() {
$("#more").click(function () {
$("#status").show();
$("#more").hide();
pageTracker._trackPageview('/?q=/more');
var u = nexturl;
getResults(u);
});
});
</script>
</head>
<body>
...
这篇关于未捕获的ReferenceError:未定义myFunction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文