每次弹出下一个问题时如何添加内容分隔符。只要它上面或下面有一个小显示器,什么样的分隔线都没有关系。我对 javascript 和 HTML 持开放态度。
例子:
q1 q2 q3 q4 (选择 q1 时,会弹出另一种形式以及内容分隔符)
q5 q6 q7 q8 (选择 q6 时,会弹出另一种形式,并带有另一个分隔符,依此类推)
这是 jsfiddle:(单击按钮查看实际操作):http: //jsfiddle.net/itay1989/ffKKN/6/
这是javascript:
$(document).ready(function () {
$('.radio div').on('click', function () {
var $this = $(this),
$parent = $this.parent(),
value = $this.attr('value');
$parent.children().removeClass('active');
$this.addClass('active');
$parent.attr('value', value);
//get all selected radios
var q1 = $('div[name="q1"].active');
var q2 = $('div[name="q2"].active');
var q3 = $('div[name="q3"].active');
var q4 = $('div[name="q4"].active');
//make sure the user has selected all 3
if (q1.length !== 0 && q2.length !== 0 && q3.length !== 0 && q4.length !== 0) {
//now we know we have 3 radios, so get their values
q1 = q1.attr('value');
q2 = q2.attr('value');
q3 = q3.attr('value');
q4 = q4.attr('value');
// activate button
$('#next_button').removeAttr('disabled');
//now check the values to display a different link for the desired
configuration
if (q1 == "AT&T" && q2 == "8GB" && q3 == "Black" && q4 == "Black") {
$('#next_button').val('att 8gb black').click(function () {
window.location.href = 'http://google.com/'
});
} else if (q1 == "AT&T" && q2 == "16GB" && q3 == "White" && q4 == "Black") {
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://bing.com/';\">another
option</input>";
} else if (q1 == "AT&T" && q2 == "16GB" && q3 == "Black" && q4 == "Black") {
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://gmail.com/';\">oops</input>";
} else if (q1 == "AT&T" && q2 == "8GB" && q3 == "White" && q4 == "Black") {
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://hotmail.com/';\">can't</input>";
} else if (q1 == "Unlocked" && q2 == "8GB" && q3 == "White" && q4 == "Black") {
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://wepriceit.webs.com/';\">red</input>";
} else if (q1 == "Unlocked" && q2 == "8GB" && q3 == "Black" && q4 == "Black") {
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://webs.com/';\">orange</input>";
} else if (q1 == "Unlocked" && q2 == "16GB" && q3 == "White" && q4 == "Black")
{
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://gazelle.com/';\">green</input>";
} else if (q1 == "Unlocked" && q2 == "16GB" && q3 == "Black" && q4 == "Black")
{
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"window.location.href='http://glyde.com/';\">blue</input>";
} else if (q1 == "AT&T") {
document.getElementById("linkDiv").innerHTML = "<input type=button
value=Next onclick=\"iphone4';\">blue</input>";
}
}
});
var questions = $(".question");
var showQuestions = function (index) {
for (var i = 0; i < questions.length; i++) {
if (i < index) {
questions.eq(i).css("display", "block");
} else {
questions.eq(i).css("display", "none");
}
}
if (index > 1) {
// only scroll to the questions after the first one is clicked
$('html, body').animate({
scrollTop : $(questions.eq(index - 1)).offset().top
},'slow');
}
}
for (var i = 0; i < questions.length; i++) {
(function (index) {
questions.eq(index).find("div[type='radio']").on("click", function () {
showQuestions(index + 2);
})
})(i);
}
showQuestions(1);
}); //]]>