我希望能够根据字符大小缩短选项菜单中的任何项目,我的尝试如下:
<script>
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)
}
});
});
</script>
html
<select id="groupId" name="groupId">
<option value="0">Select...</option>
<option selected="selected" value="1074">Nomee Project Owners Group</option>
<option value="1064">Non-Admin Group this is too long this is too long and I want it to be shortened to 10 chars with ...</option>
<option value="1043">norights</option>
<option value="1018">Promotions Group</option>
<option value="1082">PS Repeater Group</option>
<option value="1013">QC Group</option>
<option value="1056">Ryan-Group A</option>
<option value="1000">USA - SDS Admin</option>
</select>