gpt4 book ai didi

jquery - 设置显示:none to some div after I delete the text from textarea

转载 作者:行者123 更新时间:2023-12-01 06:55:52 26 4
gpt4 key购买 nike

从文本区域删除文本后如何设置显示:无到某些div

我有这个

$("#par02par04text textarea").keyup(function() {
$('#par02TextComments.comments').css('display','table-cell');
$('#par02LabelComments.comments').css('display','table-cell');
});

在我开始在文本区域中输入内容后,将显示设置为某些元素,当我从文本区域中删除文本时,我想反转它,我想设置显示:无

这是我写的

$("#par01par04text textarea").keyup(function() {
var n = $("td#par01TextComments").length;
if (n > 0) {
$('#par01TextComments.comments').css('display','table-cell');
$('#par01LabelComments.comments').css('display','table-cell');
}
else if (n == 0){
$('#par01TextComments.comments').css('display','none');
$('#par01LabelComments.comments').css('display','none');
}
});

但什么也没发生

最佳答案

当您执行 $("td#par01TextComments").length 时,您实际上获取的是 jquery 对象的长度,而不是您查询的元素的值。

首先使用文本区域的.val()获取值并检查长度

$("#par01par04text textarea").keyup(function() {
var n = $(this).val().length;
...
});

注意:

您不应在 ID 选择器前添加标记名(例如:td#someID),因为这会降低效率。

ID 选择器通常使用 native javascript 函数 getElementById()。通过在前面添加标记名,jquery 无法使用 native 函数,并且任何其他方式 getElementById 的效率都较低。

关于jquery - 设置显示:none to some div after I delete the text from textarea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9208826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com