【发布时间】:2020-05-13 09:12:53
【问题描述】:
我要控制the dropdownlist to be enabled when the checkbox is checked by respective rows. 我目前的进度我设法启用和禁用下拉列表,但它不受相应行的控制。
只要选中该复选框,就会启用所有下拉列表。
php代码部分来自html:
<td>
<select class="selection" name="lotDist[]" >
<option></option>';
==== sql queries in here ====
while ($row2 = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
{
echo '
<option value="'.$row["LotNo"].' / '.$row2["Grouping"].' - '.$row2["InBulkForm"].'">
'.$row2["Grouping"].' - '.$row2["InBulkForm"].'</option> ';
}
echo '
</select>
</td>
<td>'.$row["LoadingWeek"].'</td>
<td>
<input type="checkbox" class="chkBox" id="chkBox" name="cBox[]" value="'.$row["LotNo"].'" '.$check.'>
</td>
<script>
$(document).ready(function() {
$('.selection').attr('disabled', 'disabled');
var $checkBox = $('.chkBox');
$checkBox.on('change', function(e) {
//get the previous element to us, which is the select
var $select = $('.selection')
if (this.checked) {
$select.removeAttr('disabled');
} else {
$select.attr('disabled', 'disabled');
}
});
});
</script>
【问题讨论】:
-
嗨。您需要更具体地了解您的选择器。目前,您说当我单击此类
chkbox的任何复选框时,然后使用此类selection激活任何下拉菜单。我认为您只想在与 chkbox 相同的行中启用下拉菜单。看看这个帖子stackoverflow.com/questions/2315600/…,它将帮助您只选择同一行中的项目 -
谢谢老兄..标题搜索没有把我带到那里..hihi
标签: javascript php checkbox html-select