我想獲得默認值不要離開點擊,而是當用戶開始鍵入(所以他們知道該字段是什麼)....問題是以下內容:使用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