我有一些jquery,可以在点击时平滑地调整文本输入的大小。一切正常,除了一个小问题,当您单击远离该字段时,该字段会重置。
令人烦恼的部分是,当您在字段中输入内容,然后单击远离字段时,您输入的所有数据都会被删除。
如何让它不清除用户点击离开时输入的文本?
这是 jsfiddle
和
这是 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 fiddle : 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 )
});
关于jquery输入自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5528148/