javascript - 引用错误: $ is not defined issue

标签 javascript jquery html

我刚刚在控制台中收到一条错误消息,内容为引用错误:$未定义。这就是为什么我的表单数据在单击单选按钮后未加载。你能告诉我我的代码有什么问题吗?谢谢。

<form id='group'>
<label><input type="radio" name="group1" class="sim-micro-btn"/></label>
<label><input type="radio" name="group1" class="sim-mini-btn"/></label> 
<label><input type="radio" name="group1" class="sim-maxi-btn"/></label>
<label><input type="radio" name="group1" class="sim-mega-btn"/></label>
<label><input type="radio" name="group1" class="phone-smart-micro-btn"/></label>
<label><input type="radio" name="group1" class="phone-smart-mini-btn"/></label>
<label><input type="radio" name="group1" class="phone-smart-btn"/></label>
<label><input type="radio" name="group1" class="phone-smart-maxi-btn"/></label>
</form>

<div class="billpay-internet-add-ons">
  <div class="sim-micro-desktop">sim-micro</div>
  <div class="sim-mini-desktop">sim-mini</div>
  <div class="sim-maxi-desktop">sim-maxi</div>
  <div class="sim-mega-desktop">sim-mega</div>
  <div class="phone-smart-micro-desktop">phone-smart-micro</div>
  <div class="phone-smart-mini-desktop">phone-smart-mini</div>
  <div class="phone-smart-desktop">phone-smart</div>
  <div class="phone-smart-maxi-desktop">phone-smart-maxi</div>
</div>

<script>
$('form#group').click(function(e) {
    var className = e.target.className.replace('btn', 'desktop');    
    $('.' + className).show().siblings().hide();
});
</script>

最佳答案

您缺少对 jQuery 库的引用。

<小时/> 在使用 jQuery 之前添加 jQuery 库

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
$('form#group').click(function(e) {
    var className = e.target.className.replace('btn', 'desktop');    
    $('.' + className).show().siblings().hide();
});
</script>

关于javascript - 引用错误: $ is not defined issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21885620/

相关文章:

javascript - 如何在highchart顶部显示网格线

javascript - 检查一组单选按钮是否至少选择了一个

jquery - 在 jQuery 中,如何选择隐藏元素?

html - 如何将 div 与显示内联 block 右对齐?

javascript - jQuery : update css on one table column based on attribute of another column

html - 如何让DIV内容增长到一定程度?

javascript - 如何在着色器中处理 Float32Array? (WebGL)

jquery - 以 HTML 格式生成 PDF 文件的缩略图

javascript - 悬停时停止或暂停自动滚动功能

javascript - 如何在 body 的输入元素上委托(delegate) 'change' 事件?