使用 jQuery 在循环中获取 SELECT 标记的值


getting the value of select tag inside a loop using jquery

如何使用jquery获取循环中字段的值?前任。

<?php 
    for($counter=0; $counter<2; $counter++)
    {
       ?><select name="try<?php echo $counter; ?>">
       //bla bla bla..,.,.,.,.,. 
<?php 
    } 
 ?>

非常感谢,.,.,

$('select[name=try]').val();

或者,如果您不需要知道所选值,而是按索引知道值:

$('select[name=try]').find('option').eq(0).text(); - for text inside option node
$('select[name=try]').find('option').eq(0).attr('value') - for value attribute

其中 0 是选项节点的索引,即 0 - 第一个,1 - 第二个,依此类推。