<select class="data" multiple=""multiple"" name="data[]"> <option selected="">11111</option> <option selected="">22222</option> <option selected="">33333</option> <option selected="">44444</option> <option selected="">55555</option> </select>
select未選擇任何選項時提交表單,後臺不會接受到該數據 $_POST['data']=""或$_POST['data']=null;而是不存在$data,即isset($_POST['data'])=false。html
爲解決這個問題,當未選時讓後臺接收到一個空值,可加入一個空選項<option selected=""></option>code
<select class="data" multiple=""multiple"" name="data[]"> <option selected="" style="display:none"></option> <option selected="">11111</option> <option selected="">22222</option> <option selected="">33333</option> <option selected="">44444</option> <option selected="">55555</option> </select>