Is it possible to test how many options are in a select box?
我正在使用 jQuery 1.6.2.
我正在使用 ColdFusion 和 jQuery 动态填充选择框。
When the options are returned and stuffed inside the select box, I’d jQuery to figure out how many options there are and adjust the size attr as needed.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // load the options into the select box $("#Select").load("GlobalAdmin/ArtistUnassociatedAlbums.cfm?" + QString); // test the number of options // do a calculation // adjust the select box size | 
如何有效地获得返回的选项数量?
是的,只需使用 
| 1 | var numOfOptions = $(‘#Select option’).length; | 
只需选择选项并测试生成的 jQuery 对象的长度属性:
| 1 | console.log($("#Select option").length); | 
你可以使用这个:
| 1 | var NumOfOptions = $("#AlbumsSelect option").length; | 
尝试使用javascript的属性.length
| 1 | var length = $("option").length; | 
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/268768.html
