![](/img/trans.png)
[英]In jquery how to get the values of a particular row of a table that is selected using checkbox?
[英]How to get all selected dropdown values for a particular Id using Jquery
我有一个带有多个select
下拉菜单的表单,这些菜单以id:包开头,由用户动态添加。 我的目标是将所有这些select
下拉列表中的所有选定值放入数组中。 这是我到目前为止的代码。
$(document).ready(function() {
arr = new Array();
$(document).on('change', 'select[id ^="package"]', function() {
arr.push($(this).val());
alert(arr.join('\n')); //for testing
});
});
目前,我要做的只是将选定的值推送到数组上,而不是为特定索引设置值。 因此,如果我继续为特定的select
切换值,我将继续将值压入数组。 如何确定当前使用的选择器,以便可以在数组中获取索引以相应地修改数组?
这是您要找的东西吗?
$(document).on('change', 'select[id ^="package"]', function() {
$(this).find('option:selected').each(function(i){
arr[i] = $(this).val();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.