[英]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.