JQuery Toggle类选择所有文本

时间:2012-11-13 22:02:13

标签: javascript jquery html5 jquery-ui

我目前在屏幕一侧有一个小标签,当点击toggleClass被调用以使div更大时。同时有一个ajax调用用内容填充更大的div。但是,div中的所有文本都会被选中/突出显示,就像我将鼠标拖过整个文本一样。

有没有办法让它不被选中,或者至少在加载后取消选择它?

以下是代码:

   $(".summary-box-small").click(function () {

        $("#summary-box-container").toggleClass('summary-box-small summary-box-full', 1000);
        $.ajax({
            url: '/RuntimeSession/LoadSummaryBox',
            type: 'post',
            success: function (data) {
                $("#summary-box-container").empty().append(data);

                $("#sb-content").tabs();
                $("#tree").dynatree({
                    onActivate: function (node) {
                        alert("You activated " + node);
                    }
                });
            }
        });

        $(".summary-box-small").off('click');   //turns off the click handler so when it is expanding clicking anywhere will not make it minimized
    })

这是css:

.summary-box-small
{
    position: fixed;
    top: 400px;
    left: 0px;
    z-index: 9999;
    height: 70px;
    width: 20px;
    background-color: #cfcfcf;
}

.summary-box-full
{
    position: fixed;
    top: 400px;
    left: 0px;
    z-index: 9999;
    height: 500px;
    width: 350px;
    background-color: #cfcfcf;
    opacity: 0.9;
}

以下是AJAX调用加载的内容:

    <div id="sb-header">
    <p style="float: right">X</p>
</div>
<div id="sb-content">
    <ul>
        <li><a href="#sb-nav">Nav</a></li>
        <li><a href="#sb-dx">Dx Tracker</a></li>
    </ul>

    <div id="sb-nav">

        <p>fake content under the nav...MAKE ME A GORRAM TREE</p>
         <div id="tree">
        <ul>
            <li id="key1" title="Look, a tool tip!">item1 with key and tooltip</li>
            <li id="key2" class="selected">item2: selected on init</li>
            <li id="key3" class="folder">Folder with some children</li>
            <li id="key4" class="expanded">Document with some children (expanded on init)</li>
            <li id="key5" class="lazy folder">Lazy folder</li>
        </ul>
    </div>
    </div>
    <div id="sb-dx">
        <p>fake content</p>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

$(".summary-box-small").click()事件之外添加以下内容会做什么吗?

$("#summary-box-container").disableSelection();