缩短选择选项列表中的长选项

我希望能够使选项菜单中的任何项目缩短,具体取决于它的字符大小,我的尝试如下:

 jQuery(document).ready(function() { jQuery("#groupId").each(function(){ var myoptions = jQuery('option').length; var shorter = myoptions.substring(0,10)+"..."; if (('myoptions')>10){ jQuery(this).find('option').text(shorter) } }); });  

HTML

  Select... Nomee Project Owners Group Non-Admin Group this is too long this is too long and I want it to be shortened to 10 chars with ... norights Promotions Group PS Repeater Group QC Group Ryan-Group A USA - SDS Admin  

你可以尝试这个http://jsfiddle.net/BJ8WK/

 $("#groupId option").each(function() { if($(this).text().length>10) { $(this).text($(this).text().substring(0, 10)); } });