我在我的網頁中放置了代碼爲'n'的行中包含下拉列表的每個行中的代碼。有沒有一種方法可以在所有下拉列表都包含一個值的情況下啓用提交按鈕(即)即使一個下拉列表爲空也不能啓用該按鈕。另外,我希望提交按鈕在第一次點擊後被禁用。如何僅在while循環中的所有下拉列表都不爲空時啓用提交按鈕
我試過下面的代碼,但不起作用。
$rowIndex = 0;
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
<form>
<div>
<select name = error_type id='error_type$rowIndex' class='picker'>
<option disabled selected value> -- select an option -- </option>
<option value=2_Stage_Error>2_Stage_Error</option>
<option value=BG_Error>BG_Error</option>
</select>
</div>
$rowIndex++;
}
<input type='submit' value='SUBMIT' id='submit' onclick=report_submit()disabled
= true />
</form>
的select語句,它指定要求用戶提交表單前選擇一個值JS
<script type= "text/javascript">
$(function() {
$('.picker').on('change', function() {
var $sels = $('.picker option:selected[value=""]');
$("#submit").attr("disabled", $sels.length > 0);
}).change();
});
</script>
首先,使用'jQuery.prop',而不是'attr' – Rayon
https://jsfiddle.net/rayon_1990/dvphbf5f/1/ – Rayon
你故意把while循環外表格? – Beginner