【问题标题】:how to make the check box checked when drop down is selected如何在选择下拉菜单时选中复选框
【发布时间】:2014-01-19 14:41:18
【问题描述】:

请查看图片我正在尝试做什么我在每个 td 中都有 HTML 表格,我有下拉和复选框,当我在下拉列表中选择值时,我想让复选框选中特定 td 任何人都可以指导我怎么做。

代码:

 <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>

【问题讨论】:

  • 在更改句柄之前的ajax请求尝试$(this).closest('td').next().find('input').prop('checked', true)

标签: javascript php jquery ajax checkbox


【解决方案1】:

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

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

Jsfiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多