2

如何使用纯 JavaScript 检查选择框是否为空并提醒用户“选择框包含 0 个项目”。

4

2 回答 2

6
if (document.getElementById('select').options.length == 0) 
    alert('The selectbox contains 0 items');

http://jsfiddle.net/Gf8QK/

于 2013-02-11T17:46:14.307 回答
0

采用:

if (selectObject.options.length == 0) {
    alert('The selectbox contains 0 items');
}

http://www.w3schools.com/jsref/coll_select_options.asp

于 2013-02-11T17:46:11.977 回答