无法正常工作 errorJQuery 切换...可能很简单

发布于 2024-12-09 22:28:14 字数 1911 浏览 0 评论 0原文

我今天正在工作,决定开始使用 JQUERY 为搜索网站制作切换表...但我实际上像几天前一样开始使用 javascript 和 jquery。没有表格,它工作正常,但是当我添加表格时,它不会切换表格...我希望当您单击“过滤器搜索”时,表格会出现在下面,然后当您再次单击“过滤器搜索”时隐藏表格表...非常感谢任何帮助。这是代码(我已经在头部引用了jquery)

<div class='filtermore'>
  <h4><a>Filter Search</a></h4>
  <p style="display: none" class='jquery'>

  <table border=0 width="875">
       <tbody>
          <tr>
             <td width="164"><strong>City</strong></td>
             <td width="176"><strong>Price</strong></td>
             <td width="160"><strong>Features</strong></td>
          </tr>
           <tr>
             <td><input type="checkbox"/> City 1</td>
             <td><input type="checkbox"/> Cheap</td>
             <td><input type="checkbox"/> Financing Available</td>
             <td width="357"><input type="checkbox"/> Good for kids</td>
          </tr>
           <tr>
             <td><input type="checkbox"/> City 2</td>
             <td><input type="checkbox"/> Moderate</td>
             <td><input type="checkbox"/> Smoking</td>
             <td><input type="checkbox"/> Accepts Credit Cards</td>
          </tr>
           <tr>
             <td><input type="checkbox"/> City 3</td>
             <td><input type="checkbox"/> Expensive</td>
             <td><input type="checkbox"/> Alcohol</td>
             <td><input type="checkbox"/> Delivery</td>
           </tr>
        </tbody>
     </table>
  </p>
<script>
$("h4").click(function () {
$(".jquery").toggle("slow");
});
</script>


</div>

I was working today and decided to start using JQUERY to make a toggle table for a search site... but I literally started javascript and jquery like a couple days ago. Without the table, it works fine, but when I add the table it doesn't toggle the table...I want when you click on Filter Search for the table to come underneath and then when you click on filter search again to hide the table... Any help is much appreciated. Heres the code ( i already have jquery referenced in the head)

<div class='filtermore'>
  <h4><a>Filter Search</a></h4>
  <p style="display: none" class='jquery'>

  <table border=0 width="875">
       <tbody>
          <tr>
             <td width="164"><strong>City</strong></td>
             <td width="176"><strong>Price</strong></td>
             <td width="160"><strong>Features</strong></td>
          </tr>
           <tr>
             <td><input type="checkbox"/> City 1</td>
             <td><input type="checkbox"/> Cheap</td>
             <td><input type="checkbox"/> Financing Available</td>
             <td width="357"><input type="checkbox"/> Good for kids</td>
          </tr>
           <tr>
             <td><input type="checkbox"/> City 2</td>
             <td><input type="checkbox"/> Moderate</td>
             <td><input type="checkbox"/> Smoking</td>
             <td><input type="checkbox"/> Accepts Credit Cards</td>
          </tr>
           <tr>
             <td><input type="checkbox"/> City 3</td>
             <td><input type="checkbox"/> Expensive</td>
             <td><input type="checkbox"/> Alcohol</td>
             <td><input type="checkbox"/> Delivery</td>
           </tr>
        </tbody>
     </table>
  </p>
<script>
$("h4").click(function () {
$(".jquery").toggle("slow");
});
</script>


</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装爱人 2024-12-16 22:28:14

从技术上讲,你是在告诉

要切换的标签,而不是表格。虽然您会假设该表将从

继承,但表已被破坏且过时,并且在每个浏览器中呈现方式不同,因此您不能指望它们会关注。我会向表添加一个 ID 并在其上调用切换,或者使用 jQuery 中的子选择器(当然,您在第一周不会学到)直接定位表。像这样的事情:

<table id="mytable">

$('#mytable').toggle('slow');

// or child selector method
$('.jquery table').toggle('slow'); 

// or another method, more advanced, but the same idea would be
$('.jquery :first-child').toggle('slow');

Technically you are telling the <p> tag to toggle, not the table. While you would assume the table would inherit from the <p>, tables are busted and old-school and render differently in each browser, so you can't count on them to pay attention. I would add an ID to the table and call toggle on it, or use a child selector in jQuery (which you won't have learned the first week, for sure) to target the table directly. Something like this:

<table id="mytable">

$('#mytable').toggle('slow');

// or child selector method
$('.jquery table').toggle('slow'); 

// or another method, more advanced, but the same idea would be
$('.jquery :first-child').toggle('slow');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文