在调查问卷中添加第三个选项以"Select an Option"



我有一个调查问卷,如果用户选择选项 1 或 2 作为Select an Option他们选择的内容将确定调查表末尾显示的链接。 我不想只有 2 个选项,而是 3 个选项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";
}

js小提琴

相关内容

最新更新