【问题标题】:Uncaught ReferenceError: $ is not defined (JavaScript/HTML in PHP) [duplicate]未捕获的 ReferenceError:$ 未定义(PHP 中的 JavaScript/HTML)[重复]
【发布时间】:2016-03-06 13:11:42
【问题描述】:

我网站上的这个脚本导致了一些意外错误: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>

【问题讨论】:

  • 这意味着你在使用之前没有包含 jQuery
  • 你需要在运行这段代码之前加载jQuery。
  • 谢谢大家,我很抱歉重新发布这个..我虽然它与其他类似的问题不同

标签: javascript php html forms


【解决方案1】:

那可能是因为没有定义 jQuery。 (我假设您使用的是 juery)。

先尝试包含 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>

【讨论】:

    猜你喜欢
    • 2012-09-07
    • 2012-03-03
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多