繁体   English   中英

在调查表中添加“选择选项”的第三个选项

[英]Adding a 3rd Option to Questionnaire for “Select an Option”

我有一个调查表,如果用户为“ Select an Option选择了选项1或2,那么他们选择的内容将确定在调查表末尾显示的链接。 我希望Select an Option 3个选项,而不仅仅是2 Select an Option

这是HTML:

<a id="q1_one" class="step_button next" href="javascript:void(0)">option 1</a>
<a id="q1_two" class="step_button next" href="javascript:void(0)">option 2</a>

这是我想添加q1_three但是我不确定如何使它工作

Javascript:

function run_loading_run_4(time_delay, q1) {
timeoutID3 = window.setTimeout(
function() {
        run_loading_4(q1);
},
time_delay);
}

function run_loading_4(q1) {
    $('.run_loading_4, .loading').hide();
    $('.li_run_loading_4, li_run_loading_5, .run_loading_5, .show_end').fadeIn();
    $('#' + q1).show();
    }
$(function () {

var q1;

$(document).on('click', '.next', function (e) {
    e.preventDefault();
    $(this).parent().hide().next().fadeIn();
    if ($(this).attr('id') === "q1_one") {
            q1 = "yes";
    } else if ($(this).attr('id') === "q1_two") {
            q1 = "no";
    }

});
$(document).on('click', '.run_loading', function (e) {
    e.preventDefault();
    $(this).parent().hide().next().fadeIn();
    $('.step4 .loading').show();
    run_loading_run_1('2000');
    run_loading_run_2('4500');
    run_loading_run_3('6500');
    run_loading_run_4('8900',q1);

    });
});

以及答案:根据选择选项1或2而显示。

<div id="yes">
    <a class="step_button" href="http://link1.com">I Agree</a>
</div>
<div id="no">
    <a class="step_button" href="http://link2.com">I Agree</a>
</div>

JSFIDDLE: http : //jsfiddle.net/8r6eH/

通过添加以下行来添加选项:
HTML(第5行和第37行);

<h2>Select An Option</h2>
<a id="q1_one" class="step_button next" href="javascript:void(0)">Option 1</a>
<a id="q1_two" class="step_button next" href="javascript:void(0)">Option 2</a>
<a id="q1_three" class="step_button next" href="javascript:void(0)">Option 3</a>

<div id="yes">
    <a class="step_button" href="http://link2.com">IF QUESTION 1 = Option 1</a>
</div>
<div id="no">
    <a class="step_button" href="http://link1.com">IF QUESTION 1 = Option 2</a>
</div>
<div id="3rd_option">
    <a class="step_button" href="http://link1.com">IF QUESTION 1 = Option 3</a>
</div>

和javascript(第57行):

if ($(this).attr('id') === "q1_one") {
    q1 = "yes";
} else if ($(this).attr('id') === "q1_two") {
    q1 = "no";
} else if ($(this).attr('id') === "q1_three") {
    q1 = "3rd_option";
}

jsFiddle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM