jQuery slideDown效果不起作用

时间:2014-07-28 20:28:57

标签: javascript jquery slidedown

我有一张包含国家/地区数据的表格。对于每一行都有一个编辑按钮,当单击时,该行消失,并且包含在div中的表单将以向下滑动效果显示。我想在这个div中应用slideDown()。但是,它无法正常工作。

这是一个改编的fiddle

我的剧本:

$(document).on('click', '.glyphicon-pencil', function(event) {
    var row = $(this).closest('tr');
    var id = row.find("input[name='edit-id']").val();
    $.get('/country/' + id + '/edit', function(data) {
        row.html(data['html']).find('div').slideDown('400');
    });
});

data['html']包含呈现的表单,.glyphicon-pencil是每行中的编辑按钮。

按下编辑按钮之前的HTML示例:

<table class="table table-striped table-responsive">
        <thead>
            <tr>
                <th>Nombre</th>
                <th>Continente</th>
                <th>Capital</th>
                <th>Lengua</th>
                <th>Habitantes</th>
                <th>Moneda</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
                <tr>
                    <td>asdfasdfsdfsf</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>0</td>
                    <td></td>
                    <td>
                        <form method="POST" action="http://localhost:8000/country/all" accept-charset="UTF-8" class="pull-right"><input name="_token" value="uc1Sozi7LBtDGAxjCVQz1lDjv0bh963U1erlqMAv" type="hidden">
                            <span class="glyphicon glyphicon-pencil btn btn-xs btn-success"></span>
                            <input name="edit-id" value="1" type="hidden">
                        </form>
                    </td>
                    <td>
                        <form method="POST" action="http://localhost:8000/country/all" accept-charset="UTF-8" class="pull-right"><input name="_token" value="uc1Sozi7LBtDGAxjCVQz1lDjv0bh963U1erlqMAv" type="hidden">
                            <span class="glyphicon glyphicon-remove btn btn-xs btn-danger"></span>
                            <input name="id" value="1" type="hidden">
                        </form>
                    </td>
                </tr>

        </tbody>
    </table>

按下编辑按钮后的HTML示例:

<table class="table table-striped table-responsive">
        <thead>
            <tr>
                <th>Nombre</th>
                <th>Continente</th>
                <th>Capital</th>
                <th>Lengua</th>
                <th>Habitantes</th>
                <th>Moneda</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
    <tr><td colspan="0">
    <div style="" class="row">
        <div style="" class="form-group col-md-12">
            <div style="" class="col-md-2">
                <label for="name" class="control-label">Nombre</label>
            </div>
            <div style="" class="col-md-10">
                <input class="form-control" autocomplete="off" placeholder="Nombre del país" id="update-name" name="name" value="asdfasdfsdfsf" type="text">
            </div>
        </div>
        <div style="" class="form-group col-md-12">
            <div style="" class="col-md-2">
                <label for="continent" class="control-label">Continente</label>
            </div>
            <div style="" class="col-md-10">
                <input class="form-control" autocomplete="off" placeholder="Continente donde se encuentra" id="update-continent" name="continent" value="" type="text">
            </div>
        </div>
        <div style="" class="form-group col-md-12">
            <div style="" class="col-md-2">
                <label for="capital" class="control-label">Capital</label>
            </div>
            <div style="" class="col-md-10">
                <input class="form-control" autocomplete="off" placeholder="Ciudad capital" id="update-capital" name="capital" value="" type="text">
            </div>
        </div>
        <div style="" class="form-group col-md-12">
            <div style="" class="col-md-2">
                <label for="language" class="control-label">Lengua</label>
            </div>
            <div style="" class="col-md-10">
                <input class="form-control" autocomplete="off" placeholder="Lengua oficial" id="update-language" name="language" value="" type="text">
            </div>
        </div>
        <div style="" class="form-group col-md-12">
            <div style="" class="col-md-2">
                <label for="population" class="control-label">Habitantes</label>
            </div>
            <div style="" class="col-md-10">
                <input class="form-control" autocomplete="off" placeholder="Número total de habitantes" id="update-population" name="population" value="0" type="text">
            </div>
        </div>
        <div style="" class="form-group col-md-12">
            <div style="" class="col-md-2">
                <label for="currency" class="control-label">Moneda</label>
            </div>
            <div style="" class="col-md-10">
                <input class="form-control" autocomplete="off" placeholder="Moneda que se usa" id="update-currency" name="currency" value="" type="text">
            </div>
        </div>
        <div style="" class="form-group col-md-12">
            <span class="glyphicon glyphicon-floppy-disk btn btn-success"></span>
            <span class="glyphicon glyphicon-ban-circle btn btn-primary"></span>
            <input name="update-id" value="1" type="hidden">
        </div>
    </div>
</td></tr>

        </tbody>
    </table>

1 个答案:

答案 0 :(得分:0)

slideDown()用于显示所选元素,不会对已显示的元素产生影响。在使用slideDown()

之前,您需要隐藏所需的元素
$(document).on('click', '.glyphicon-pencil', function(event) {
    var row = $(this).closest('tr');
    var id = row.find("input[name='edit-id']").val();
    $.get('/country/' + id + '/edit', function(data) {
        row.html(data['html']).find('div.row').hide().slideDown('400');
    });
});

http://jsfiddle.net/WD8X3/1/