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 に答える