【发布时间】:2021-10-14 01:31:42
【问题描述】:
我有一个网页,它使用 javascript 和 ajaxpage 在另一个页面中加载一个页面,而无需刷新。代码如下所示:
<a href="javascript:ajaxpage('r/gd.php','releases');">LINK</a>
单击 LINK 会将“r/gd.php”加载到我标记为“发布”的 DIV 中。我从这个网站获得了代码的主干:
这一切都很好,直到我尝试使用复选框来过滤加载页面上的 DIV 内容。我想做的是有一系列具有唯一 ID 的复选框,如下所示:
<input type="checkbox" id="all"> Show All
<input type="checkbox" id="red"> Red
<input type="checkbox" id="orange"> Orange
<input type="checkbox" id="yellow"> Yellow
这些将在选中/取消选中时显示/隐藏各种 DIV,其中包含一系列如下类:
<div id="box" class="all red"><?php echo $gdclock; ?></div>
<div id="box" class="all red orange"><?php echo $gdheart; ?></div>
<div id="box" class="all orange"><?php echo $gdblue; ?></div>
<div id="box" class="all red orange yellow"><?php echo $gdwhite; ?></div>
<div id="box" class="all yellow"><?php echo $gdclearsplat; ?></div>
<div id="box" class="all red yellow"><?php echo $gdredblack; ?></div>
我不确定如何在以我这样做的方式加载的页面上完成此操作。我使用了诸如 this 和 this 之类的示例,它们在访问 URL 时效果很好,但是一旦我在动态加载的页面上使用相同的代码,它什么也不做。
我在这里缺少什么吗?这是link to my webpage(最好在桌面上查看)。如果您单击左侧栏中的所有专辑,则会加载一个充满黑胶唱片的页面,顶部带有复选框。我想根据颜色进行过滤(使用如上所述的类/ID)并隐藏其他所有内容。一次激活多个复选框是理想的。
【问题讨论】:
-
嗨,欢迎来到 SO。请先拨打tour。然后阅读how to ask questions here。之后编辑问题以符合准则并提供minimal reproducible example 用于调试详细信息(显示问题不是php 的编译版本)。另请阅读:Can I just link to my website?。问题必须始终是自包含的,无需使用外部资源。到目前为止,您对 JS 进行了哪些尝试?
-
PS:一个 ID 必须是唯一的。多次使用一个 ID 是无效的 HTML。
-
您能否包含函数
ajaxpage的代码以及来自Ajax 调用的一些示例数据?
标签: javascript html css