-1

所有,我有以下选择:

<select name="options_1" id="options_1" class="select_me"> 
    <option>1</option> 
    <option>2</option>  
</select>

我的页面上有多个具有相同类的选择。当我更改其中一个选择时,我想获取选择的名称或 ID,然后是下划线后面的值。

谁能让我知道该怎么做?谢谢!

4

3 回答 3

2
$(document).ready(function() {
   $("SELECT[id^=options]").bind('change', function() {
       var fullId = $(this).attr('id');
       var idParts = fullId.split('_');
//       idParts[0] would be options
//       idParts[1] would be 1
   });
});
于 2012-06-28T16:44:37.080 回答
0

使用类作为 change() 处理程序的选择器

演示:http: //jsfiddle.net/QjEkS/

$('select.select_me').change(function(){
   var id=this.id;
   var num_val= id.split('_').pop();
    alert( 'ID: '+id +', Num: '+num_val);    
});
于 2012-06-28T16:44:47.327 回答
0
$('.select_me').on('change', function(){
   var id = this.id,  // original id
       number =  id.substr( id.indexOf('_') + 1 ); // numeric part of id
});

工作样本

于 2012-06-28T16:48:00.390 回答