我想获得默认值不要离开点击,而是当用户开始键入(所以他们知道该字段是什么)....问题是以下内容:使用jquery改变输入内容的形式
当我使用onchange而不是onfocus时,它在开始键入时保留默认值。如果它把我在做的事情弄糊涂到facebook上,看看他们的搜索框是如何工作的......那就是我要做的。
<script>
function uFocus() {
$('#fakeusername').hide();
$('#username').show();
$('#username').focus();
}
function uBlur() {
if ($('#username').attr('value') == '') {
$('#username').hide();
$('#fakeusername').show();
}
}
</script>
<input style='width:202px;height:25px;margin-top:8px;font-size:14px;color:gray;' type='text' name='fakeusername' id='fakeusername' value=' Username' onfocus='uFocus()' />
<input style='width:202px;height:25px;margin-top:8px;font-size:14px;color:#000000;display: none' type='text' name='username' id='username' value='' onblur='uBlur()' />
我喜欢这个想法。点击某些东西很容易,变得分心,然后忘记你应该输入的内容。或忘记建议的格式(电话号码是否有破折号?)。 – DOK 2012-03-10 19:03:08