Jquery - 单击href时显示/隐藏Textarea

时间:2015-12-17 14:25:32

标签: jquery

我有一个href和textarea,我使用链接因为按钮不适合我的设计。问题是我想在单击标记<a>时显示textarea并将文本从“回复(显示)”更改为“回复(隐藏)”我的代码无效。

$(document).ready(function(){
    $("#replyshow").click(function(){
    var rep = $("#replyshow").text();
    event.preventDefault();
    if (rep == "Reply (show)") {
        $("#reply").show(500);
        rep = $("#replyshow").text("Reply (hide)");
    } else {
        $("#reply").hide(500);
        rep = $("#replyshow").text("Reply (show)");
    }
    });
});

1 个答案:

答案 0 :(得分:0)

@Jagadeesh评论说,您在<ul class="list-unstyled"> <li class="btn" ng-repeat="data in eventsData"> {{data.title}} </li> </ul> 函数调用中缺少事件。您的代码应如下所示:

&#13;
&#13;
click
&#13;
$(document).ready(function(){
		$("#replyshow").click(function(event){ // event is added here!
		  var rep = $("#replyshow").text();
		  event.preventDefault();
		  if (rep == "Reply (show)") {
			  $("#reply").show(500);
			  rep = $("#replyshow").text("Reply (hide)");
		  } else {
			  $("#reply").hide(500);
			  rep = $("#replyshow").text("Reply (show)");
		  }
		});
	});
&#13;
&#13;
&#13;