0

我正在使用 qTip2 显示表格行的工具提示:

   @foreach (var item in Model)
        {
            <tr id="@(item.ShopListID)">
                <td id="name@(item.ShopListFoodID)" class="shoptablename">@Html.DisplayFor(modelItem => item.Name)
                </td>
                <td id="amnt@(item.ShopListFoodID)" class="shoptableamount">@Html.DisplayFor(modelItem => item.Amount)
                </td>
            </tr>

        }

我想为每个“金额”字段提供工具提示,所以我像这样启动工具提示:

    // Use ajax to add tooltip for food with stock amount
    $('.shoptableamount').qtip($.extend({}, myStyle, {
        content: {
            text: 'Loading...', // The text to use whilst the AJAX request is loading
            ajax: {
                url: '/Shop/GetFoodAmount', 
                type: 'GET',
                data: { id: $('.shoptableamount').attr('id') } 
            }
        }
    }));

但是,由于我选择使用该类,所以我只获得了第一个 tr 的 id,并且无论我将鼠标悬停在哪一行上,我仍然会获得一些工具提示内容作为第一行。我尝试使用 $(this) 来选择 id,但我没有工作。

我需要一个可以选择当前悬停元素的选择器...

希望可以在这里得到一些帮助...感谢任何反馈...

谢谢....

4

1 回答 1

1

我尝试在悬停时获取 tooptip,这是我的代码,您必须为所有不同的 td 提供工具提示

<html>
<head>
<title>Test Qtip on Hover</title>
<script src="jquery.1.6.1.min.js"></script>
<script src="jquery.qtip-1.0.0-rc3.min.js"></script>

    <style>
    .className {
        color: red;
    }

    .classValue {
        color: green;
    }
    </style>

    <script type="text/javascript">
        $(document).ready(function() {

            $('.classValue').each(function() {
                $(this).qtip({
                    content : $(this).text() + "_" + $(this).attr('id')
                });
            });
        });
    </script>
    </head>
    <body>
        <table border="1">
            <thead>
                <th>Name</th>

                <th>Value</th>

            </thead>
            <tbody>
                <tr>
                    <td id="name1" class="className">test1</td>
                    <td id="value1" class="classValue">test1Val</td>
                </tr>
                <tr>
                    <td id="name2" class="className">test2</td>
                    <td id="value2" class="classValue">test2Val</td>
                </tr>
                <tr>
                    <td id="name3" class="className">test3</td>
                    <td id="value3" class="classValue">test3Val</td>
                </tr>
            </tbody>
        </table>
    </body>
    </html>

希望这可以帮助。

于 2011-11-17T14:52:24.200 回答