jQuery的/ JavaScript的:阵列 [英] jquery/javascript: arrays

查看:89
本文介绍了jQuery的/ JavaScript的:阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Javascript / jQuery的一个初学者,我希望有人能帮助我以下内容:

I am a begginer with Javascript/jQuery and I hope someone can help me with the following:

我有一个简单的表格(7题; 3单选按钮/每个问题的答案 - 除了有8个可能的选择问题5),并根据所选择的答案,当视图建议用户点击我要显示有关建议(38可能建议组合)的形式之下。
我已经给A,B,C,...值单选按钮和我在一个阵列收集它们。
该脚本提醒阵列的部分工作正常。
我想不通的部分,我显示建议根据不同的价值观数组中

I have a simple form (7 questions; 3 radio buttons/answers per question - except for question 5 with 8 possible choices ) and based on the selected answers, when user clicks on 'view-advice' I want to display relevant advices (combination of 38 possible advices) below the form. I have given "a", "b", "c",... values to radio buttons and I am collecting them in an array. The part where the script alerts the array works ok. I can't figure out the part where I display the advices depending on the values in the array.

我想AP preciate您的帮助!谢谢!

I'd appreciate your help! Thanks!

下面是code:



var laArray = new Array();

$('.button-show-advice').click(function(){

    $(":radio:checked").each(function(i){
        laArray[i] = $(this).val();
        if (laArray == ["a","d","g","j","m","u"]) {
        $("#advice-container, #advice1, #advice2").show(); // something is wrong here :(
            };
    })
    alert(laArray) // testing to see if it works

})

推荐答案

会很高兴地看到HTML code。但我猜你想要做这样的事情:

Would be nice to see the HTML code. But I guess you want to do something like this:

var laArray = [];
var compareValues = function(arr1, arr2) {
  $(arr1).each(function(index, el) {
   if(el !== arr2[index]) {
     return false;
   }
  });
  return true;
};

$('.button-show-advice').click(function(){
    $(":radio:checked").each(function(i){
        laArray.push($(this).val());        
    });
   if(compareValues(laArray,["a","d","g","j","m","u"])) {
      $("#advice-container, #advice1, #advice2").show();
   }  
});

编辑:更新了code,忘了}); ...

这篇关于jQuery的/ JavaScript的:阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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