同樣的事情。您將事件綁定到所有涉及的SELECT。如果你有一個ID(#選擇器),你不需要指定SELECT。在回調,你現在必須明確地檢索每個控件的值:
$('#selectId1, #selectId2, #selectId3').on('change', function() {
var s1 = $('#selectId1').val();
var s2 = $('#selectId2').val();
var s3 = $('#selectId3').val();
//url
control('ocupantes-aptos/dashboard?SELECTID =' + s1 , 'content');
});
或者你可以給一個特定的類所有這些控件:
$('select.grupo1').on('change', ...
與
<select id="selectId1" class="grupo1">
...
注意: jQuery還具有高效地對一個表單或一組控件進行序列化的功能,因此您不需要指定所有這些val()
。
例
在這個例子中,我們發送所有的「grupo1的價值觀,只要其中的任何變化。該HTML看起來像一個系列的元素:
<select name="s[1]" class="grupo1">...</select>
<select name="s[2]" class="grupo1">...</select>
或者更短,使用 「#grupo2選擇」,而不是 「select.grupo1」:
<div id="grupo2">
<select name="s[1]">...</select>
<select name="s[2]">...</select>
jQuery的(這裏採用的「選擇。grupo1" 的選擇)
var sels = $('select.grupo1');
sels.on('change', function() {
// We want to use the control() function, so
// we need to build the URL. We may have problems with too many selects,
// and in that case we will need to modify control().
control('ocupantes-aptos/dashboard?' + sels.serialize(), 'content');
});
的PHP將得到:
$selects = $_GET['s'];
foreach ($selects as $num => $val) {
// Here for example num=1, and val = the selected value of s[1].
}
搜索PHP阿賈克斯 - 例如https://www.google.com/search?q=php%20ajax%20more% 20%20%%20select – mplungjan