gpt4 book ai didi

javascript - 如何在选择下拉菜单时选中复选框

转载 作者:行者123 更新时间:2023-12-02 17:52:44 24 4
gpt4 key购买 nike

请查看我正在尝试执行的操作,我在每个 td 下拉列表和复选框中都有 HTML 表,当我在下拉列表中选择值时,我想为特定 td 选中该复选框,任何人都可以指导我如何做。

enter image description here

代码:

 <td style="width:141px" > <select name="mySelect" id="mySelect" class="edit1 route '.$rows["net_id"].'" >         
<option value="-1">Choose..</option>';


$query = "SELECT route FROM routestable WHERE `clientid` = '$client_id' ";

$result = mysql_query($query);

while ($rows1 = mysql_fetch_assoc($result))
{


if(strlen($rows1['route'])>0 && $rows1['route']==$rows['route']){
print' <option value="'.$rows1['route'].'" selected>'.$rows1['route'].' </option>';}

else{

echo '<option value="' . $rows1['route'] . '"> ' . $rows1['route'] . '</option>';

}

}


echo '</select>
</td>


<td style="width:200px" id="CPH_GridView1_Status1'.$rows['net_id'].'" class="edit2 status1 '.$rows["net_id"].' "><input type="checkbox" style="margin:0 0 0 93px;" name=""/></td>

ajax

<script>

$(document).ready(function(){

$('.edit1').on('change', function(){


arr = $(this).attr('class').split( " " );
var clientid=document.getElementById("client").value;
account_id=document.getElementById("account_id").value;


$.ajax({ type: "POST",
url:"clientnetworkpricelist/routestatusupdate.php",
data: "value="+$(this).val()+"&rowid="+arr[2]+"&field="+arr[1]+"&clientid="+clientid+"&account_id="+account_id,


success: function(res){
data = jQuery.parseJSON(res); //added line
alert('Saved Successfully!');
$('#CPH_GridView1_Status'+arr[2]).empty();
$('#CPH_GridView1_Status'+arr[2]).append(data.status);
$('.ajax').html($(this).val());
$('.ajax').removeClass('ajax');
}});


}


);


});


</script>

最佳答案

要在下一个 td 尝试中选中复选框

$(this).parent().next().find('input:checkbox').attr("checked",true);

Jsfiddle

关于javascript - 如何在选择下拉菜单时选中复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21213942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com