【问题标题】:show submit button when clicking textarea单击文本区域时显示提交按钮
【发布时间】:2014-06-28 20:29:35
【问题描述】:

我有很多文本区域。

当我点击 textarea 时,它的形状会完美展开。而不是我尝试添加将显示提交按钮的代码(点击后)。

我的代码可以工作,但效果不佳 - 我需要点击多次,直到按钮出现。

为什么会这样?

echo "<form id='addComment".$fIndex['id']."' action='#' method='post' >";
    echo "<p style='margin: 0 15px 0 10px'><textarea class='expandTextarea' refID='".$fIndex['id']."'></textarea></p>";
    echo "<p><a href='#' class='addComment button3d' refID='".$fIndex['id']."' id='addCommentButton".$fIndex['id']."' style='display: none'>Submit</a></p>";
echo "</form>";




$(function() {
    $(".expandTextarea").focus(function(){
        var element = $(this);
        var refID = element.attr("refID");
//      alert(refID);



        $('textarea.expandTextarea').focus(function () {
            $(this).animate({ height: "200px" }, 500); 
        //  $('.addComment').show();
            $('#addCommentButton' +refID).show();
        });




    });
}); 

【问题讨论】:

  • 因为第二个.focus() 在第一个内部,所以您需要先聚焦一次以激活第二个焦点,然后再取消聚焦并再次聚焦以触发它。
  • 谢谢!........

标签: javascript


【解决方案1】:

要让两个动作都使用一个焦点:

$(function() {
    $(".expandTextarea").focus(function(){
        var element = $(this);
        var refID = element.attr("refID");
        element.animate({ height: "200px" }, 500); 
        $('#addCommentButton' +refID).show();
    });
}); 

【讨论】:

    猜你喜欢
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    • 2020-01-30
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多