如果输入框为空,则显示标签,如果有文本,则隐藏标签

如果输入框为空,则显示标签,如果有文本,则隐藏标签

问题描述:

如果联系表单输入框为空,是否可以显示<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();
})