Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在文本区域变空时隐藏按钮,并在按钮变空后立即显示';它不再是空的了?_Jquery_Html_Hide - Fatal编程技术网

Jquery 如何在文本区域变空时隐藏按钮,并在按钮变空后立即显示';它不再是空的了?

Jquery 如何在文本区域变空时隐藏按钮,并在按钮变空后立即显示';它不再是空的了?,jquery,html,hide,Jquery,Html,Hide,我的jQuery代码: $(document).ready(function(){ var textboxHomeValue = $('#post-textbox textarea'); $(document).on('keyup, keydown', '[data-listener="textboxHome"]', textboxHome); function textboxHome(e) { if($.trim(textboxHomeValue).

我的jQuery代码:

$(document).ready(function(){

    var textboxHomeValue = $('#post-textbox textarea');

    $(document).on('keyup, keydown', '[data-listener="textboxHome"]', textboxHome);
    function textboxHome(e) {
        if($.trim(textboxHomeValue).length > 0){
            $('#post-button-disabled').hide();
            $('#post-button').show();
        } else {
            $('#post-button-disabled').show();
            $('#post-button').hide();
        }
    }
});
开头很好。一旦我在文本区域中键入内容,按钮就会出现,但如果我删除文本,它不会再次消失。

尝试使用该方法

要调用函数,请执行以下操作:

$("#yourTextarea").change(textBoxHome);

您需要
$。修剪
您的
textarea
值,而不是包含
textarea
的jQuery对象:

$(document).on('keyup','textarea',function()){
if($.trim($(this.val()).length==0){
$('button').show();
}否则{
$('button').hide();
}
});

只有文本区是空的,我才在这里检查此项

//最初隐藏按钮
$('#btn').hide();
//文本区域键控功能
$('textarea[name=txtarea]').keyup(function(){

如果($.trim($(this).val()).length@AyumiTakanashi没有问题,如果这个答案解决了您的问题,请不要忘记验证它。
$("#yourTextarea").change(textBoxHome);