Uncaught ReferenceError: $ is not defined (JavaScript/HTML in PHP)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34040293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught ReferenceError: $ is not defined (JavaScript/HTML in PHP)
提问by Lucián Bla?ek
This script I have on my site is causing some unexpected error: Uncaught ReferenceError: $ is not defined
it should rewrite function of enter to act as a tab within the inputs on site form instead of submitting that form.
我网站上的这个脚本导致了一些意外错误:Uncaught ReferenceError: $ is not defined
它应该重写 enter 函数以充当网站表单输入中的选项卡,而不是提交该表单。
<script type="text/javascript">
$('input').keypress(function(e) {
if (e.which == 13) {
<--! says error is here within the $ symbol -->
$(this).next('input').focus();
e.preventDefault();
}
});
</script>
回答by Nelson Owalo
Thats probably because jQuery isn't defined. (I'm assuming you are using juery).
那可能是因为未定义 jQuery。(我假设您正在使用 juery)。
Try including jQuery first:
首先尝试包含 jQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$('input').keypress(function(e) {
if (e.which == 13) {
<--! says error is here within the $ symbol -->
$(this).next('input').focus();
e.preventDefault();
}
});
</script>