我的多选框有问题。我尝试使用jQuery选择多个值,但只选择了最后一个,有人可以帮我吗?这是我的代码:
<script>
$(function(){
<?php
foreach ($selectdefaults as $s):
?>
$('#q<?php echo $s['campsetjoin']['campid'];?> select').val('<?php echo $s['campsetjoin']['setid'];?>');
<?php
endforeach;
?>
});
</script>
这是我的HTML源代码(这是用PHP生成的):
<table>
<tr>
<td>
<form id="s1" name="camps">
<input type="hidden" name="camid" value="1" />
<strong> Camp 1 </strong>
</form>
</td>
<td align="right" id="q1">
<select name="qsets" multiple="multiple">
<option value="1">common set</option>
<option value="2">test set</option>
</select>
</td>
<td>
<input type="button" value="update" cid="1" class="btncdsave" />
</td>
</tr>
<tr>
<td>
<form id="s9" name="camps">
<input type="hidden" name="camid" value="9" />
<strong> Camp 2 </strong>
</form>
</td>
<td align="right" id="q9">
<select name="qsets" multiple="multiple">
<option value="1">common set</option>
<option value="2">test set</option>
</select>
</td>
<td>
<input type="button" value="update" cid="9" class="btncdsave" />
</td>
</tr>
<tr>
<td>
<form id="s10" name="camps">
<input type="hidden" name="camid" value="10" />
<strong> Camp 3 </strong>
</form>
</td>
<td align="right" id="q10">
<select name="qsets" multiple="multiple">
<option value="1">common set</option>
<option value="2">test set</option>
</select>
</td>
<td>
<input type="button" value="update" cid="10" class="btncdsave" />
</td>
</tr>
</table>
所以我需要选择多个选择框的值。我可以获取表单ID并选择框值id以供选择。谢谢你的帮助。
答案 0 :(得分:1)