javascript - jQuery/JavaScript - 隐藏所有带 ID 的元素并保留所有其他元素

标签 javascript php jquery mysql

<分区>

我正在开发产品目录页面。每个产品都有一个带有 id 的特定 div 元素。例如:

<div id="2354234" class="product">Here is name, image and description of the product</div>
<div id="2354235" class="product">Here is name, image and description of the product</div>
<div id="2354236" class="product">Here is name, image and description of the product</div>
<div id="2354237" class="product">Here is name, image and description of the product</div>
<div id="2354238" class="product">Here is name, image and description of the product</div>
<div id="2354239" class="product">Here is name, image and description of the product</div>
<div id="2354240" class="product">Here is name, image and description of the product</div>
<div id="2354241" class="product">Here is name, image and description of the product</div>
<div id="2354242" class="product">Here is name, image and description of the product</div>
<div id="2354243" class="product">Here is name, image and description of the product</div>

并且这些产品都加载了从 MySQL 数据库获取的 PHP。在页面的末尾我有分页。每页仅显示 10 个产品。所有产品都是 300,所以我有 30 页,每页 10 个产品。

当用户实时单击按钮而不重新加载以隐藏除 6 之外的所有其他元素(例如具有特定 ID)时,我如何使页面更新。

你能给我一些建议吗?我可以很好地使用 jQuery 和 PHP,所以我需要一个如何完成这件事的建议。

提前致谢!

最佳答案

使用 CSS attribute selector应该这样做:

$('div[id]').not('#2354234,#2354235,#2354236').hide();

关于javascript - jQuery/JavaScript - 隐藏所有带 ID 的元素并保留所有其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34314940/

相关文章:

javascript - 如何使用 jQuery 每秒减少 HTML 元素的值?

php - Netbeans 8 和 xdebug 非常非常慢

jQuery 循环效果 : scrollHorz not working properly

javascript - JQuery在重新加载时将事件类添加到父类

javascript - 如何使用 jQuery 测量元素宽度

javascript - 在 JavaScript 中导入带有子对象和数组的对象

javascript - 将 Tumblr 嵌入博客的最佳方式

javascript - 用按钮切换页面中的js src

php - 使用 PHP 从图像创建定格动画视频

php - 尽管时区有效,但设置默认时区不起作用