Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定:我有一个文本框和一个隐藏按钮。
需要:当文本框既不为空也不为空时,显示按钮。当文本框为空或为空时,隐藏按钮。
问题:我该怎么做?我应该使用 jQuery 并绑定到文本框的 keyup 事件吗?
当然,这个keyup活动听起来是个好主意。您可能会执行以下操作:
keyup
$("textarea").keyup(function() { if ($(this).val().replace(/ /g, '') == '') $("#id-of-button").show(); else $("#id-of-button").hide(); });