Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用纯 JavaScript 检查选择框是否为空并提醒用户“选择框包含 0 个项目”。
if (document.getElementById('select').options.length == 0) alert('The selectbox contains 0 items');
http://jsfiddle.net/Gf8QK/
采用:
if (selectObject.options.length == 0) { alert('The selectbox contains 0 items'); }
见http://www.w3schools.com/jsref/coll_select_options.asp