[英]jquery input auto-resize
我有一些jQuery,可以在單擊時平穩地調整文本輸入的大小。 一切正常,除了單擊字段以外的小問題時,該字段將重置。
令人討厭的部分是,當您在該字段中鍵入內容,然后在該字段之外單擊時,將刪除您輸入的所有數據。
我如何才能不清除用戶單擊時輸入的文本?
和
這是jQuery:
var inputWdith = '250px';
var inputWdithReturn = '140px';
$(document).ready(function() {
$('input').focus(function(){
$(this).val(function() {
$(this).val('');
});
$(this).animate({
width: inputWdith
}, 400 )
});
$('input').blur(function(){
$(this).val('Enter info...');
$(this).animate({
width: inputWdithReturn
}, 500 )
});
});
可用的js小提琴: http : //jsfiddle.net/NcwZA/1/
$('input').focus(function(){
if($(this).val()=='Enter info...'){
$(this).val('');
}
//animate the box
$(this).animate({
width: inputWdith
}, 400 )
});
$('input').blur(function(){
if($(this).val()==''){
$(this).val('Enter info...');
}
$(this).animate({
width: inputWdithReturn
}, 500 )
});
如果該字段為空白,則只需要執行模糊處理即可。
$('input').blur(function(){
if ($(this).is(":empty")){
$(this).val("Enter info...")
.animate({
width: inputWdithReturn
}, 500 );
}
});
問題出在blur
事件中。 沒有條件不替換用戶輸入的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.