2014-09-24 69 views
0

我面临的问题是,我的div.hide不工作,因为它只是显示,每当我点击链接“回复”它不会隐藏。如何隐藏textarea?

的JavaScript

<script type="text/javascript"> 
$('body').on('click','a.btnGG',function(){ 
    var va=$(this).data('comment_id'); 
    $("#parent_id").val(va); 
    $("#formReply").attr("va",$("#formReply").attr("va") + va); 
    $(".formms").hide(); 
    $(this).after('<div class="formms">'+$(".gg").html()+'</div>'); 

    $("#hides").onclick(function(){ 
     $(".gg").css("display","block"); 
    }); 
</script> 

TPL

<a href="javascript:;" id="hides" class="btnGG" > reply</a> 
<div class="gg" style="display:none;"> 
    <form action="/commenter/web/index.php" id="formReply" method="Post" > 
     <input type = "hidden" name ="m" value = "{$m}" /> 
     <input type="hidden" name="comment_id" id="comment_id" value="{$data.comment_id}"/> 
     <input type = "hidden" name="post_id" value="{$req.post_id}" /> 
     <!-- <input type = "hidden" name="user_id" value="{$req.user_id}" /> --> 
     <input type = "hidden" name ="c" value = "do_add_comment_reply" /> 
     <input type="hidden" name="parent_id" id="parent_id" value=""/> 

     <textarea class="form-control" name="message" placeholder="Please leave a reply of the comment "></textarea> 
     <input type="submit" id="btn_reply" name="btn_reply" class="btn btn-primary" value="Reply"> 

    </form> 
</div> 

我初学编程的。

+2

有多种可能性为什么出了问题,可能是因为你还没有缠你代码在文档就绪函数中,这可能是因为你没有关闭click函数的括号,这可能是因为'onclick'是一个js函数,你将它与jQuery混合,只需使用'click'来代替看看他们是否解决你的问题! – 2014-09-24 07:03:39

+0

首先阅读上面的注释。接下来,“val(va)”是什么意思?它不存在。你的下一行中没有attar“va”。请提供一些关于您的目标的更多信息以及需要完成的工作,因为它不是很清楚... – 2014-09-24 07:05:04

+0

我看不到代码段中的任何元素,其中有一个类'formms'在您尝试的时候把它藏起来。 – Teemu 2014-09-24 07:05:25

回答

-1
<a href="javascript;" id="hides" class="btnGG" > reply</a> 
<div class="gg" style="display:none;"> 
    // Code 
</div> 

它更改为类似

<a href="#" id="hides" class="btnGG" > reply</a> 
<div class="gg" id="testid" style="display:none;"> 
    // Code 
</div> 

和使用脚本像

$(document).ready(function(){ 
    $("#hides").onclick(function(){ 
     $("#testid").toggle("show"); 
    }); 
}); 
0

很难告诉你与你的代码做什么。如果你只是想显示格或隐藏点击回复按钮,有一个完整的代码(TPL文件):

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
</head> 
<body> 




<a href="javascript:;" id="hides" class="btnGG" > reply</a> 
<div class="gg" style="display:none;"> 
    <form action="/commenter/web/index.php" id="formReply" method="Post" > 
     <input type = "hidden" name ="m" value = "{$m}" /> 
     <input type="hidden" name="comment_id" id="comment_id" value="{$data.comment_id}"/> 
     <input type = "hidden" name="post_id" value="{$req.post_id}" /> 
     <!-- <input type = "hidden" name="user_id" value="{$req.user_id}" /> --> 
     <input type = "hidden" name ="c" value = "do_add_comment_reply" /> 
     <input type="hidden" name="parent_id" id="parent_id" value=""/> 

     <textarea class="form-control" name="message" placeholder="Please leave a reply of the comment "></textarea> 
     <input type="submit" id="btn_reply" name="btn_reply" class="btn btn-primary" value="Reply"> 

    </form> 
</div> 


<script type="text/javascript"> 
    $('body').on('click','a.btnGG',function() { 
     $(".gg").toggle(); 
    }); 
</script> 
</body> 
</html>