繁体   English   中英

使用jQuery获取Id以进行可编辑

[英]Getting Id with jquery for jeditable

我一直在做一个网站,现在正在管理它的管理部分,以便可以轻松地管理用户,可以轻松地修改文章等。我想使用jeditable以便使管理员真正易于使用。

JEdi​​table的一部分正在工作(p标签正在成为输入),但是我无法通过ajax请求发送产品ID。

这是我目前拥有的html代码(由php生成):

    <table class="admin_list">
        <tr>
            <th style="width: 110px;">First Name</th>
            <th style="width: 110px;">Last Name</th>
            <th style="width: 100px;">Date of Birth</th>
            <th style="width: 200px;">Email</th>
            <th style="width: 140px;">Address</th>
            <th style="width: 112px;">Postal Code</th>
            <th style="width: 112px;">Town</th>
            <th style="width: 120px;">Country</th>
            <th style="width: 115px;">Login</th>
            <th style="width: 42px;">Action</th>
        </tr>

        <tr class="2">
            <td><p class="editable">Another</p></td>
            <td><p class="editable">User</p></td>
            <td><p class="editable">11/11/1911</p></td>
            <td><p class="editable">user@email.com</p></td>
            <td><p class="editable">Address</p></td>
            <td><p class="editable">56130</p></td>
            <td><p class="editable">Town</p></td>
            <td><p class="editable">2</p></td>
            <td><p class="editable">bob</p></td>
            <td>
                <a href="http://localhost/monline/private_html/musiconline/?delete/user/2">D</a>
                <a href="">U</a>
                <a href="">D</a>
            </td>
        </tr>

        <tr class="1">
            <td><p class="editable">Daniel</p></td>
            <td><p class="editable">Lucas</p></td>
            <td><p class="editable">10/04/1990</p></td>
            <td><p class="editable">dan@email.com</p></td>
            <td><p class="editable">myAddress</p></td>
            <td><p class="editable">12345</p></td>
            <td><p class="editable">myTown</p></td>
            <td><p class="editable">8</p></td>
            <td><p class="editable">dan</p></td>
            <td>
                <a href="http://localhost/monline/private_html/musiconline/?delete/user/1">D</a>
                <a href="">U</a>
                <a href="">D</a>
            </td>
        </tr>
    </table>

    <input type="text" class="edit_id" value="" />

这是我写的jQuery:

    $( function() {
        $('.admin_list tr').hover( function() {
            $('.edit_id').attr( 'value', $(this).attr('class') );
        });

        $('.editable').editable("http://localhost/monline/private_html/musiconline/?admin/edit/users/" + $('.edit_id').attr('value'), {
            indicator : 'Saving...',
            onblur : 'submit',
            method : 'PUT'
        });
    });

如您所见,当鼠标悬停时,我正在获取当前行的ID(我想避免),但是,当我提交页面时,该ID并未在可编辑的url中设置。

有谁知道如何对它进行排序,就像我想在管理面板中使用就地编辑器一样?

作为一个可选的请求,我如何获得围绕单击的输入的tr的类? 我已经尝试过$(this).parent()。parent()。attr('class')

谢谢丹

您是否尝试过(在没有悬停功能的情况下, $(this).closest('tr').attr('value')应该指向相对的<tr>

 $('.editable').editable("http://localhost/monline/private_html/musiconline/?admin/edit/users/" + $(this).closest('tr').attr('value'), {
        indicator : 'Saving...',
        onblur : 'submit',
        method : 'PUT'
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM