如果输入不为空则显示按钮 [英] Show button if input is not empty

查看:32
本文介绍了如果输入不为空则显示按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是 JavaScript 专家,所以我需要简单代码方面的帮助.我有一个按钮可以清除输入字段的值.

I am not much of a JavaScript guru, so I would need help with a simple code. I have a button that clears the value of an input field.

如果输入字段为空,我希望它(按钮)被隐藏,反之亦然(如果输入字段中有文本则可见).

I would like it (the button) to be hidden if input field is empty and vice versa (visible if there is text inside the input field).

解决方案可以是纯 JavaScript 或 jQuery,没关系.越简单越好.

The solution can be pure JavaScript or jQuery, it doesn't matter. The simpler, the better.

推荐答案

if(!$('input').val()){
    $('#button').hide();
}
else {
    $('#button').show();
}

最简单的形式;)

这篇关于如果输入不为空则显示按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆