构建jQuery多选问卷

时间:2014-08-16 11:25:09

标签: javascript jquery multi-select

我必须构建jQuery多选问卷。 代码是:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head lang="en">
    <meta ccontent="text/html; charset=utf-8" http-equiv="content-type">
    <title>multi select questionnaire</title>


    <script src="js/jquery-1.11.1.js"></script>



</head>
<body>
<div id="questions">

</div>
<script type="text/javascript">
    var currentQuestion = null;
    var questionIndex = 0;

    // Your list of questions. Each question has an answer (either a,b or c)
    // and then a set of "options" in the question
    var questions = [
        {
            'answer': 'c',
            'question': 'What doesn\'t fit?',
            options: ['Dog', 'Capybara', 'Pizza']
        },
        {
            'answer': 'b',
            'question': 'What is 9*9',
            options: ['9', '81', '99']
        }
    ];

    // Detect when the submit button is clicked and check if the question
    // was answered correctly
    $('input[type="submit"]').click(function() {
        var val = $('#questions').find('input:checked').val();
        if(currentQuestion) {
            if(currentQuestion.answer == val) {
                alert("Nice work!");
                showQuestion();
            } else {
                alert("Nope!");
            }
        }
        return false;
    });

    // Set the value of an option in the question
    function setRadioLabel(radioId, text) {
        $('label[for="' + radioId + '"]').find('span.ui-btn-text').text(text);
    };

    // Show a random question
    function showQuestion() {
        // Grab next question, and increment so we get a new one next time
        var random = questions[questionIndex++ % questions.length];

        $('#question').text(random.question);

        $('input[type="radio"]').attr('checked', false).checkboxradio('refresh');

        setRadioLabel('radio1', random.options[0]);
        setRadioLabel('radio2', random.options[1]);
        setRadioLabel('radio3', random.options[2]);
        currentQuestion = random;
    };

    // Start the question stuff off
    showQuestion();
</script>
</body>
</html>

我无法在页面上显示任何内容,因为我在行$('input[type="radio"]').attr('checked', false).checkboxradio('refresh');中收到以下错误: 未捕获的TypeError:undefined不是函数。 这是我遇到的唯一错误,无法确定问题所在。

0 个答案:

没有答案