gpt4 book ai didi

jquery输入自动调整大小

转载 作者:行者123 更新时间:2023-12-01 06:30:36 25 4
gpt4 key购买 nike

我有一些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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com