[英]How can i get one value from different select options with the same name in the same form
[英]How can i select values from different select types having same class and get their value
我正在使用上面的代码设计选择类型和复选框,现在我想获取每个选择类型的值并将其添加并在文本框中显示结果。
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);
},
和我的其余代码
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);
}
不知道这是否行得通,但尝试
$(".month option:selected").each(function(){
console.log($(this).val())
});
为什么不通过呢?
onChange="add(this);"
function add(this){
var value = this.value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.