如果输入框为空,则显示标签,如果有文本,则隐藏标签 [英] If input box is empty show label, if there is text, hide label

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

问题描述

如果联系表单输入框为空,是否可以显示<label>,然后在有人开始输入文本后将其隐藏?

Is there a way that I can show a <label> if a contact form input box is empty and then hide it once someone starts entering text?

这是我的标记示例

<label for="name">Name *</label>
<input type="text" id="name" name="name" value=""/>

推荐答案

尝试一下:

$("#name").bind("keyup", function(e) {
    $('label[for="name"]').hide();
})

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

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