0

我有以下 HTML。

<div id = "aa">
        <table width="100%">
            <tbody>
                <!-- ngRepeat: msg in globalChat -->
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="8">
                    <td class="ng-binding" ng-1375781897068="9">
                        A
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="10">
                    <td class="ng-binding" ng-1375781897068="11">
                        B
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="12">
                    <td class="ng-binding" ng-1375781897068="13">
                        C
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="14">
                    <td class="ng-binding" ng-1375781897068="15">
                        D
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="16">
                    <td class="ng-binding" ng-1375781897068="17">
                        E
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="18">
                    <td class="ng-binding" ng-1375781897068="19">
                        F
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="20">
                    <td class="ng-binding" ng-1375781897068="21">
                        G
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="22">
                    <td class="ng-binding" ng-1375781897068="23">
                        H
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="24">
                    <td class="ng-binding" ng-1375781897068="25">
                        I
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="msg in globalChat" ng-1375781897068="26">
                    <td class="ng-binding" ng-1375781897068="27">
                        J
                    </td>
                </tr>
                <tr class="ng-scope" ng-repeat="ms`enter code here`g in globalChat" ng-1375781897068="28">
                    <td class="ng-binding" ng-1375781897068="29">
                        K
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

我已经使用 AngularJS 来呈现值

我只是希望,如果我单击 div 中的任何文本,那么只有该特定文本应该在 div 中突出显示。通过单击 div 中的其他文本,应取消选择先前选择的文本并选择新文本。我怎样才能做到这一点?

4

3 回答 3

1

这是你要找的东西:

http://jsfiddle.net/bT8vs/

jQuery:

$(document).ready(function(){
    $('div p').click(function(){
       $('div p').css("background-color", "transparent");
       $(this).css("background-color", "yellow");
    });
});
于 2013-08-06T10:00:45.847 回答
1

这与 imconnell 的答案几乎相同,但适用于给定的布局:http: //jsfiddle.net/rpqvX/7/

$(function() {
    $("td.ng-binding").click(function() {
        $("td.ng-binding").removeClass("highlight");
        $(this).addClass("highlight");
    });
})
于 2013-08-06T10:05:24.147 回答
0

作为替代方案,请查看以下 jQuery 插件:

highlight: JavaScript 文本高亮 jQuery 插件

于 2013-08-06T10:09:18.387 回答