【发布时间】:2011-11-29 15:52:57
【问题描述】:
只要我的<label for=""> 与input 名称和ID 匹配,我就有一些提供占位符的jQuery。然而,事实并非如此,所以我决定只使用<span> 作为占位符。有人可以帮助更改我的 jQuery 以使我正在使用的 <span> 类“持有人”工作吗?目标是让占位符保持焦点,在输入存在时消失,然后在输入消失时重新出现。
这是我正在使用的 HTML:
<div id="placeholder">
<span class="holder">This is the placeholder...</span>
<%= f.text_area :body, :id =>"Placeholder" %>
</div>
还有我目前的 jQuery:
$(document).ready(function() {
$('textarea').keyup(function() {
if ($(this).val().length) {
$('label[for="' + $(this).attr('name') + '"]').hide();
} else {
$('label[for="' + $(this).attr('name') + '"]').show();
}
});
});
谢谢!
【问题讨论】:
标签: jquery placeholder