![](/img/trans.png)
[英]Uncaught ReferenceError ReferenceError: question is not defined
[英]Uncaught ReferenceError: $$ is not defined
我正在尝试以编程方式创建一个饼图 ,希望将其转换为可重用的React组件。 基本上,我需要一个可单击的饼图,单击时每个切片都会扩展为整个饼图。 我正在尝试按照本教程制作饼图,而在底部,我尝试了一块JS 。 我最终遇到了Uncaught Reference Error: $$ is not defined.
这是错误消息的屏幕截图。
我的理解是,这不是jQuery ,而是Vanilla JS。 我不确定这是否是真的。 我通过CDN导入了jQuery ,但仍然遇到相同的错误。 我读了这篇SO帖子 ,我认为$$
只是一种变量名表示法。
这是我在index.html
拥有的代码,毫无突破。
<body>
<div class="pie">20%</div>
<div class="pie">60%</div>
<script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>
<script type="text/javascript">
$$('.pie').forEach(function(pie) {
var p = parseFloat(pie.textContent);
var NS = "http://www.w3.org/2000/svg";
var svg = document.createElementNS(NS, "svg");
var circle = document.createElementNS(NS, "circle");
var title = document.createElementNS(NS, "title");
circle.setAttribute("r", 16);
circle.setAttribute("cx", 16);
circle.setAttribute("cy", 16);
circle.setAttribute("stroke-dasharray", p + " 100");
svg.setAttribute("viewBox", "0 0 32 32");
title.textContent = pie.textContent;
pie.textContent = '';
svg.appendChild(title);
svg.appendChild(circle);
pie.appendChild(svg);
});
</script>
</body>
是什么导致错误? 我误会了吗 我正在关注的教程过时/错误吗? 谢谢!
包括以下这些:
function $$(selector, context) {
context = context || document;
var elements = context.querySelectorAll(selector);
return Array.prototype.slice.call(elements);
}
根据作者Lea Verou的说法,她提到:
在书中,$$()的定义在引言中给出,但是由于这是节选,因此不包含该内容。
您是否尝试过在$$('.pie')
上使用单$而不是双$$,所以您的代码就像$('.pie')
?
并检查您是否已经包含jQuery
这是有用的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.