JavaScript错误显示在浏览器中
javascript error is shown in the browser
javascript 代码不起作用。你能告诉我为什么它不起作用吗?无论内容高度如何,我都想要两个大小相等的div。我在一个容器里拿了两个div,并在两个div里面放了一些虚拟文本。浏览器引发此错误。"未捕获的引用错误:未定义 $"。
$(document).ready(function() {
var leftHeight = $('#left-block').height();
var rightHeight = $('#right-block').height();
if (leftHeight > rightHeight) {
rightHeight = leftHeight;
} else {
leftHeight = rightHeight;
}
$('#left-block').css('height','rightHeight');
$('#right-block').css('height','rightHeight');
});
* {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
.container:before,
.container:after {
content: "";
display: table;
}
.left-block,
.right-block {
float: left;
padding: 20px;
width: 50%;
}
.left-block {
background: #e4e4e4;
}
.right-block {
background: whitesmoke;
}
<div class="container">
<div id="left-block" class="left-block">
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
</div>
<div id="right-block" class="right-block">
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
<p>demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text</p>
</div>
</div>
浏览器引发此错误。"未捕获的引用错误:未定义 $"。
这意味着未定义$
。 在这种情况下,$
指的是jQuery。您正在尝试使用 jQuery 库中的功能,但实际上您根本没有将其包含在您的文档中。
要解决此问题,只需从jQuery网站下载jQuery,并使用以下命令将其包含在HTML文件中:
<script src="path/to/jquery/jquery.min.js"></script>
(将path/to/jquery
更改为相对于将 jQuery 下载到的 HTML 文档的文件夹路径,并将jquery.min.js
更改为下载版本的确切文件名)。
此外,您不是将高度设置为变量中包含的值,而是将它们设置为字符串值。改变:
$('#left-block').css('height','rightHeight');
$('#right-block').css('height','rightHeight');
自:
$('#left-block').css('height', rightHeight);
$('#right-block').css('height', rightHeight);
请注意,这样一来,您的leftHeight
变量永远不会被使用。
你需要添加对jQuery的引用。例如:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" ></script>
或者你可以通过首先从jQuery网站下载它来托管它与你的网站。
相关文章:
- 如何检测浏览器并根据浏览器显示视频
- 为什么浏览器显示原型属性不同
- Javascript,基于浏览器显示图像
- 浏览器显示/执行表单字段的警报
- 跨浏览器显示模态对话框替换
- 谷歌浏览器 - 显示和隐藏元素
- 请求节点.js后浏览器显示错误
- ajax如何防止浏览器显示ajax url
- 可以'无法在JS中访问document.cookie中的cookie,但浏览器显示存在cookie
- 为什么我的浏览器显示“;未获取引用错误“;在这里
- 如何在用户不刷新浏览器的情况下不断地向用户浏览器显示更新
- ie浏览器显示警告值“未定义”;但火狐和chrome显示出了实际价值
- 不完全回复来自服务器的警告消息用ie8浏览器显示
- 哪个事件导致浏览器显示HTML验证消息
- 检测浏览器-显示不同的链接
- 使浏览器显示下载文件列表
- 浏览器显示过时的JSP页面,用户必须手动刷新
- 浏览器显示区域的位置
- 浏览器显示'reactComponent未定义'在控制台
- 浏览器显示缓存文件而不是重定向