0
$('.choose').each(function(){
getval.push($(this).val());
for(i=0;i<=getval.length;i++){
console.log(getval[i]);
}
$('.choose').each(function(){
getval.push($(this).val());
for(i=0;i<=getval.length;i++){
console.log(getval[i]);
}
選擇元素通常有兩個要訪問的值。首先有價值被髮送到服務器,這很容易:
$("#myselect").val();
// => 1
第二個是文本值的選擇。例如,使用下面的選擇框:
<select id="myselect">
<option value="1">Mr</option>
<option value="2">Mrs</option>
<option value="3">Ms</option>
<option value="4">Dr</option>
<option value="5">Prof</option>
</select>
如果你想獲得字符串「先生」,如果被選中(而不是僅僅「1」),你會做的是,在下面的方式第一個選項:
$("#myselect option:selected").text();
// => "Mr"
簡單:
$('.choose').change(function(){
var value = $(this).val(); // You can use the variable value wherever you want
});
$(this).val() will give you the value of the select box which are changing even if there
是1000 pf的與同級別選擇框。