Php 更改子按钮的属性

Php 更改子按钮的属性,php,jquery,Php,Jquery,我必须选择一个盒子。还有两个按钮。按钮被禁用。当selectbox更改时,按钮将被启用 <select class="form-control" id="target_category" name="target_category"> <?php $categories = $categoryObj->deepestCategories(); ?> <option value="-

我必须选择一个盒子。还有两个按钮。按钮被禁用。当selectbox更改时,按钮将被启用

<select class="form-control" id="target_category" name="target_category">
                    <?php $categories = $categoryObj->deepestCategories(); ?>
                    <option value="-1">Kategori Seç</option>
                    <option value="0">Kategori Yok</option>
                    <?php
                        foreach($categories as $category){
                            echo '<option value="'.$category['id'].'">(ID: '.$category['id'].') '.$category['category'].'</option>';
                        }
                    ?>
                </select>
                <span class="input-group-btn">
                    <button disabled="disabled" name="move_category_button" id="move_category_button" class="btn btn-default" type="submit"><span class="glyphicon glyphicon-move"></span> Taşı</button>
                </span>  

<select class="form-control" id="target_location" name="target_location">
                <?php $locations = array('Türkiye','Çin','Hindistan','Nepal','Pakistan'); ?>
                <option value="-1">Menşei Seç</option>
                <?php
                    foreach($locations as $location){
                        echo '<option value="'.$location.'">'.$location.'</option>';
                    }
                ?>
            </select>
            <span class="input-group-btn">
                <button disabled="disabled" name="move_location_button" id="move_location_button" class="btn btn-default" type="submit"><span class="glyphicon glyphicon-move"></span> Taşı</button>
            </span> 

您的按钮不是您选择的子按钮,而是同级按钮的子按钮

使用
.next()
获取同级按钮容器,然后使用
.children()
获取按钮。另外,与添加和删除属性相比,最好将
disabled
属性作为布尔值使用

$('#target_location, #target_category').change(function(){
    var val = $(this).val();

    if (val != -1){
        $(this).next('input-group-btn').children('button').prop('disabled', false);
    } else {
        $(this).next('input-group-btn').children('button').prop('disabled', true);
    }
});

按钮不是选择框的子项,需要选择下一个同级项

$('#target_location, #target_category').change(function(){
    val = $(this).val();

    if (val != -1){
        $(this).next('span').find('button').removeAttr('disabled');
    } else {
        $(this).next('span').find('button').attr('disabled','disabled');
    }
})
$('#target_location, #target_category').change(function(){
    val = $(this).val();

    if (val != -1){
        $(this).next('span').find('button').removeAttr('disabled');
    } else {
        $(this).next('span').find('button').attr('disabled','disabled');
    }
})