简体   繁体   English

我如何从具有相同类的不同选择类型中选择值并获取其值

[英]How can i select values from different select types having same class and get their value

I am designing select types and check boxes with above code, now i want to get value of each select type and add them and show result in text box. 我正在使用上面的代码设计选择类型和复选框,现在我想获取每个选择类型的值并将其添加并在文本框中显示结果。

success: function(data) {
  //console.log(data.students);

  var student = "";
  $.each(data.students, function(key, value) {
    student += value +'<input type="checkbox" name="' + value + '" value="' + key + '">Months <select name="amount" class="month" onChange="add();"><option value="">Select months</option><option value="1">1</option><option value="3">3</option><option value="6">6</option><option value="12">12</option></select>';
  });

  student += 'Total Amount <input  type="text" value"" id="total">';
  student += '<button type="submit" > Pay</button>';
  $('#hide').hide();
  $('#student-list').show().html(student);
},

and my rest code 和我的其余代码

function add(){

         //var value = ($(this).find("option:selected").text());
      // var value= $("option:selected" ).text();
    //  var  value= $(".option :selected").val();


        var value= $(".month :selected").val();
        sum(value);
        //var val   =$(this).val();
        //alert(value);

    }   

    function sum(value){

        var total=0;

        total=value*1000;

        alert(total);
        //$('#total').val(total);

    }

not sure if this will work but try 不知道这是否行得通,但尝试

$(".month option:selected").each(function(){
    console.log($(this).val())
});

why not pass this ? 为什么不通过呢?

onChange="add(this);"

function add(this){
   var value = this.value; 
}

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

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