【问题标题】:On click remove div with js [closed]单击使用 js 删除 div [关闭]
【发布时间】:2016-05-10 04:00:47
【问题描述】:

如果我点击 X,它将删除 div:

$('#close').on('click', function(){
  $(this).closest('div').remove();
})
<div class="single_add">

    <i id="close" class="fa fa-times-circle">X</i>

    ads

</div>

在 jsfiddle 中工作的代码

http://jsfiddle.net/Ny346/161/

但是当我将它上传到我的服务器时它不起作用

http://www.bohgames.com/js.html

有什么问题?

【问题讨论】:

  • 你没有包含 jquery 脚本检查控制台错误它说Uncaught ReferenceError: $ is not defined
  • 是的@guradio 是对的。此错误是未包含的 jQuery 库的典型错误。

标签: javascript jquery html web-services


【解决方案1】:
<div class="single_add">

<i id="close" class="fa fa-times-circle" onclick="this.parentElement.style.display = 'none';">X</i>

ads

</div>

【讨论】:

    【解决方案2】:

    您没有包含 jquery 脚本检查控制台是否显示错误 Uncaught ReferenceError: $ is not defined

    包含jquery脚本就可以了

    【讨论】:

      【解决方案3】:

      您还没有包含 jQuery 库。 将此添加到您的页面头部或底部

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      

      【讨论】:

        【解决方案4】:

        你没有包含 JQuery 脚本,

        &lt;script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-01-20
          • 1970-01-01
          • 1970-01-01
          • 2016-12-14
          • 1970-01-01
          • 2016-04-19
          • 1970-01-01
          相关资源
          最近更新 更多