如何显示/隐藏问卷中的按钮 [英] How to show/hide buttons in questionnaire

查看:139
本文介绍了如何显示/隐藏问卷中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用if show/hide/statement/function来使按钮下拉,但是我似乎无法使其正常工作.我尝试了jquery和javascript,但似乎无法正常工作.我愿意使用javascript和jquery来完成此任务.

I'm trying to get the buttons to dropdown with an if else show/hide /statement/function but I can't seem to get it to work. I've tried jquery and javascript but it doesn't seem to work. I'm willing to use javascript and jquery to accomplish this.

以下是我要完成的一些示例(注意:这仅出于示例原因而故意完成,我非常清楚这不是有效的代码):

Here are some examples I'm trying to accomplish (Note: this was done on purpose for example reasons only and I am very aware that this is not a valid code):

        if (q1 == "iphone3gs") {
            $('.show(iphone3gs)').val('.hide(iphone4 iphone4s iphone5 
iphone5s)').click(function () {
                window.location.href = 'iphone3gs'
            });

        if (q1 == "iphone4") {
            $('.show(iphone4)').val('.hide(iphone3gs iphone4s iphone5 
iphone5s)').click(function () {
                window.location.href = 'iphone3gs'
            });

        if (q1 == "iphone4S") {
            $('.show(iphone4s)').val('.hide(iphone3gs iphone4 iphone5 
iphone5s)').click(function () {
                window.location.href = 'iphone3gs'
            });

        if (q1 == "iphone5") {
            $('.show(iphone5)').val('.hide(iphone3gs iphone4s iphone4 
iphone5s)').click(function () {
                window.location.href = 'iphone3gs'
            });

        if (q1 == "iphone5s") {
            $('.show(iphone5s)').val('.hide(iphone3gs iphone4s iphone5 
iphone4)').click(function () {
                window.location.href = 'iphone3gs'
            });

这是jsfiddle中的完整代码: http://jsfiddle.net/wLY7C/3/

Here's the full code in jsfiddle: http://jsfiddle.net/wLY7C/3/

未经任何编辑的代码: http://jsfiddle.net/nwxLM/

Code without any editing: http://jsfiddle.net/nwxLM/

推荐答案

您的代码都搞砸了!请使用易于理解的变量和ID名称.

Your code is all messed up! Please use variable and id names that are easily understandable.

这是演示.只需为每个问题选择任何答案,然后看看会发生什么.按钮文本按此顺序为q1 q2 q3 q4.

Here is a demo. Just select any answer for each question and see what happens. The button text is q1 q2 q3 q4 in that order.

您正在使用q4来检查颜色,实际上它是电话类型,所以没有.我所做的更改足以使您了解您的问题.

You are using q4 to check for color when it is actually phone type and so no. I changed just enough to make you understand your problem.

$('#next_button').val("" + q1 + " " + q2 + " " + q3 + " " + q4); return;

//now check the values to display a different link for the desired  configuration
if (q1 == "AT&T" && q2 == "8GB" && q3 == "Black" && q4 == "iPhone-3GS") {
     $('#next_button').val('att 8gb black').click(function () {
          window.location.href = 'http://google.com/'
      });
} 

要显示隐藏的元素,请使用$(selector).show(),要隐藏元素,请使用$(selector).hide().不要将ID与您为元素提供的类名和值混淆.

To show an hidden element use $(selector).show() and to hide an element use $(selector).hide(). Do not confuse with the IDs with the class name and the value you have provided to the elements.

这篇关于如何显示/隐藏问卷中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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