通过XML数据使用jQuery和HTML进行分页 [英] Paging Through XML Data Using jQuery and HTML

查看:104
本文介绍了通过XML数据使用jQuery和HTML进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含问题列表的XML文件。我想在HTML页面加载并以单选按钮加载答案时加载列表中的第一个问题。当其中一个单选按钮被选中时,我想显示结果以及继续按钮。继续按钮将转到XML文件中的第二个元素。



所以,到目前为止我已经有了以下内容:

  function generateQuestion(i){
$(document).ready(function(){
$ .get('quiz.xml',function (d){
alert('Loaded XML');
$(d).find('question')。get(0,function(){
alert('Loaded Question' );
var $ question = $(this);
var questionContent = $ question.attr(content);
$(questionContent).appendTo(#quizQuestion);
});
});
});
}

但是,问题的内容永远不会加载到元素中。当我去获取文档中的第一个元素时,它看起来像挂起。我的猜测是,没有重载将对象注入函数。

我是否正确?任何人有任何快速的资源,显示一个基本的问题类似的例子,我想要生成?



更新:我已经更新了以下代码,它似乎(b)
$ b

  function generateQuestion(i){
$(document).ready(function (){
$ .get('quiz.xml',function(d){
var $ question = $(d).find('question')。get(i); $ b $ (问题内容);
$(questionContent).appendTo(#quizQuestion);
});
});
}

有什么想法?



<$ p $ ($)$($)$。$($)$($)$($) (问题内容);
$(questionContent).appendTo(#quizQuestion);
});

另一种选择是重新包装对象

(pre> $。get('quiz.xml',function(d){
var question = $(d).find('question')。get(0 );
var questionContent = $(question).attr('content');
alert(questionContent);
(questionContent).appendTo(#quizQuestion);
});

另外,我不确定为什么在函数调用中包含$(document).ready 。你什么时候调用这个函数。如果它在文档加载之后,那么你并不需要它。


I've got an XML file that contains a list of questions. I'd like to load the first question in the list when an HTML page loads and load the answers as radio buttons. When one of the radio buttons is selected, I'd like to display the results as well as a continue button. The continue button would go to the second element in the XML file.

So, I've got the following thus far:

function generateQuestion(i) {
    $(document).ready(function() {
        $.get('quiz.xml', function(d) {
            alert('Loaded XML');
            $(d).find('question').get(0, function() {
                alert('Loaded Question');
                var $question = $(this);
                var questionContent = $question.attr("content");
                $(questionContent).appendTo("#quizQuestion");
            });
        });
    });
}

However, the content from the question is never loaded in the element. It looks like it hangs when I go to get the first element in the document. My guess is that there is no overload to inject the object into the function.

Am I correct? Anyone have any quick resources that shows a basic quiz-like example like I'm looking to generate?

UPDATE: I've updated the code to the following and it seems to get caught on the attribute property:

function generateQuestion(i) {
    $(document).ready(function() {
        $.get('quiz.xml', function(d) {
            var $question = $(d).find('question').get(i);
            var questionContent = $question.attr('content');
            alert(questionContent);
            $(questionContent).appendTo("#quizQuestion");
        });
    });
}

Any ideas?

解决方案

the get() function returns the non-wrapped set element in this case it would be the xml element.

$.get('quiz.xml', function(d) {
    var question = $(d).find('question :eq(0)');
    var questionContent = question.attr('content');
    alert(questionContent);
    $(questionContent).appendTo("#quizQuestion");
});

the other alternative is to re-wrap the object

$.get('quiz.xml', function(d) {
    var question = $(d).find('question').get(0);
    var questionContent = $(question).attr('content');
    alert(questionContent);
    $(questionContent).appendTo("#quizQuestion");
});

Also, I'm not sure why your including the $(document).ready inside the function call. When are you calling the function. if its after the document load then you don't really need that.

这篇关于通过XML数据使用jQuery和HTML进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆