0

我想切换锚标记文本,我在 div 中有一个锚标记,当用户单击回复时,评论框打开,文本应该变为关闭,反之亦然,但问题是在文本变为关闭后,文本仍然关闭在显示和隐藏之间切换清楚地工作......

<a id="reply" href="#">reply</a>
<div id="replyuser" style=" position:absolute;">
    <asp:TextBox ID="txt1" CssClass="txtbox" TextMode="MultiLine" runat="server"></asp:TextBox><br />
    <asp:Button ID="btnreply" Text="send" runat="server" CssClass="btn" />
</div>

jquery如下

$(document).ready(function() {
    $("#replyuser").hide();

    $("#reply").click(function() {
        $("#replyuser").toggle(function() {
            $("#reply").text("close");
        });
    });
});
4

2 回答 2

3

尝试在单击时替换文本:

您处于按钮的上下文中,然后尝试$(this)在它获得点击事件时引用它,然后切换#replydiv 并检查文本。如果这有文本reply将其更改为close.

把它放在css中:

#replyuser {
    display:none;
}

然后使用此脚本:

$("#reply").click(function() {
   $("#replyuser").toggle();
   ($(this).text() === "reply") ? $(this).text("close") : $(this).text("reply");
});

最后的小提琴

于 2013-04-06T05:42:44.970 回答
0
    $(document).ready(function() {
                $("#replyuser").hide();

                $("#reply").click(function() {

                    $("#replyuser").toggle(function(e) {
                           $(this).is(":visible") ? $("#reply").text("close") : $("#reply").text("reply");                         
                    });

                });
            });

$(this) 是对 $("#replyuser") 控件SO 链接的引用, :visible 是可见控件的选择器(惊讶的是 :))。所以逻辑上 .is 检查 $("#replyuser") 是否可见。

于 2013-04-06T05:40:12.647 回答