简体   繁体   English

如何阻止文本区域消失?

[英]How can I stop the textarea from disappearing?

I have a form that adds comment from the user: 我有一个添加用户评论的表格:

<textarea name="comment" id="comment_box" placeholder="Share your thoughts" cols="175" rows="9"></textarea>     

<input type="button" name="add_comment" id="add_comment_button" value="Add comment" 
 onclick="add_comment_js('comment_form','{$type}')">

Once I click on the button "Add comment" the textarea disappears (I think using jquery), no css files included. 一旦我点击按钮“添加评论”,文本区域就消失了(我想使用jquery),其中没有CSS文件。

A big functions.js file is linked also, I suspect this method inside the javascript file has to do with the disappearance: 还链接了一个很大的functions.js文件,我怀疑javascript文件中的此方法与消失有关:

  function add_comment_js(form_id,type)
  {
    var formObjectData = $('#'+form_id).serialize()+'&mode=add_comment';

    $.post(page,formObjectData,
    function(data)
    {
        if(!data)
            alert("No data");
        else
        {
            if(data.cid)
            {
                get_the_comment(data.cid,"#latest_comment_container");
                $("#"+form_id).slideUp();
            }
        }
    },'json');
}

Why is the textarea hiding after I post the comment? 为什么在发布评论后隐藏文本区域? What's wrong? 怎么了?

$("#"+form_id).slideUp(); is hiding the form when this function runs. 运行此函数时隐藏表单。 Remove that line and the textarea should persist. 删除该行,文本区域应保持不变。 Slideup "Hides the matched elements with a sliding motion." Slideup“以滑动方式隐藏匹配的元素”。 Here's the jQuery API reference for that function. 这是该函数的jQuery API参考

remove this line form your code 从您的代码中删除此行

$("#"+form_id).slideUp();

final result should look : 最终结果应为:

function add_comment_js(form_id,type)
{
    var formObjectData = $('#'+form_id).serialize()+'&mode=add_comment';

    $.post(page,formObjectData,
    function(data)
    {
        if(!data)
            alert("No data");
        else
        {
            if(data.cid)
            {
                get_the_comment(data.cid,"#latest_comment_container");
            }
        }
    },'json');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM