javascript - ReferenceError:$ 未在 /code.js 10:1 中定义
问题描述
我正在尝试使用 JavaScript 和 jQuery 制作一个生活模拟器(基于 Web),当我获取代码并运行它时,控制台说在我添加此代码之前ReferenceError: '$' is not defined at /code.js 10:1
jQuery工作:我不知道问题是什么。这是我的代码:$
$('#name').html(name);
var name = prompt('What is your name?');
var money = 1000;
var hunger = 100;
var hygiene = 100;
var sleep = 100;
var favColor = prompt('What is your favorite color?\nIf there is 2 words, combine them.\nDo not capitalize the color.', 'green');
var start = true;
$('#name').html(name);
$('#color').css('color', favColor);
function bed() {
$('#bed').html('You are sleeping');
var sleeping = setInterval(function() {
if (sleep == 100) {
this.clearInterval();
$('#bed').html('You are awake');
} else {
sleep++;
}
}, 500);
}
解决方案
在代码的标题部分添加 jQuery。
推荐阅读
- vb.net - 如何修复“FormatException:输入字符串的格式不正确”
- spring-security - Spring Cloud Config服务器集成spring security后不工作
- sql - SQLite 从表中删除 10000 行
- php - PHP 文件大小只检查第一张图片
- powershell - ForEach 方法后 PowerShell 长度的奇怪行为
- mysql - SQL 跳过 select 的第一个值
- python - 使用 qt Creator 时单击按钮时如何运行 .py 文件
- telegram - 电报 - 发布链接未在网络中打开
- javascript - 如何在 VueJS 中的表格行单击上加载不同的组件?
- python - 在帧之间移动小部件(tkinter & python 3)