jquery - 允许用户从 5 个不同的圣经版本中选择一个来查看引用资料。实现这一目标的最佳方法是什么?隐藏CSS类? Ajax ?

标签 jquery css ajax reference

我将在我正在制作的网站上引用圣经经文。当用户点击圣经经文时,它会展开以显示该经文。

所以 Genesis 1:1 点击时,变成 Genesis 1:1 In the the beginning God create the heaven and earth etc.

在设置面板页面的顶部,我想让他们从 5 个不同的版本中选择一个。因此,当他们单击该经文时,它会在网站上所有经文引用的这 5 个版本中的 1 个版本中显示。

执行此操作的最佳方法是什么?我考虑过为每个引用设置 5 个不同的 SPAN,但我可以在一个页面上创建多达 10 个或更多的引用,这将是 40 个额外的隐藏跨度……ajax 会更好吗?对于这样的事情,您建议采用什么方法?

最佳答案

您可以将这些经文存储在 XML 文件中,然后使用 Ajax 根据标题返回特定的经文。您的代码可能看起来像这样...

HTML...

<ul>
    <li class="verse"><a href="#">Deuteronomy 31:6</a></li>
    <li class="verse"><a href="#">Joshua 1:9</a></li>
</ul>

jQuery...


        $(".verse a").click(function (event) {
            event.preventDefault();
            $link = $(this).parent();
            $title = $(this).text();
            $.ajax({
                type: "GET",
                url: "verses.xml",
                dataType: "xml",
                success: function (xml) {
                    $(xml).find('verse').each(function () {
                        var title = $(this).find('title').text();
                        // match titles
                        if ($title == title) {
                            var text = $(this).find('text').text();
                            $link.empty().text(title + ': ' + text);
                        }
                    });
                }
            });
        }); // end

XML 文件...

<?xml version="1.0" encoding="utf-8"?>
<verses>
  <verse>
    <title>Deuteronomy 31:6</title>
    <text>Be strong and courageous. Do not be afraid or terrified because of them, for the LORD your God goes with you; he will never leave you nor forsake you.</text>
  </verse>
  <verse>
    <title>Joshua 1:9</title>
    <text>The LORD gave this command to Joshua son of Nun: "Be strong and courageous, for you will bring the Israelites into the land I promised them on oath, and I myself will be with you.</text>
  </verse>
</verses>

关于jquery - 允许用户从 5 个不同的圣经版本中选择一个来查看引用资料。实现这一目标的最佳方法是什么?隐藏CSS类? Ajax ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5645212/

相关文章:

html - 链接 css 文件会删除背景

html - 如何在垫输入字段中聚焦时更改垫图标颜色?

c# - Request.Files 始终为空

javascript - 为什么ajax成功调用后jquery会中断?

javascript - ajax加载后jQuery可以重置父高度吗?

javascript - jQuery mouseenter 技巧?

javascript - 在循环数组时发出 json 请求和存储值的正确方法是什么?

javascript - 即使使用解除绑定(bind)程序,如何防止 jQuery 多次触发?

jquery - 如何在 MVC 应用程序中返回 JSON 并循环遍历 jQuery 中返回的 json?

javascript - 未捕获的类型错误 : $scope. mvp.$setUntouched 不是函数 angularjs 1.4