禁用元素的调用函数
如果您想扩展超过 20 个字符的 input type=text
,我有一个可以完美运行的函数。我的问题是,如何将此功能应用于禁用的输入?为了更好地理解我的函数的行为,请检查我在小提琴上的示例: http://jsfiddle.net/DCjYA/168/
$('input[type!="submit"]').focus(function(){
if ($(this).val().length > 20) {
$(this).attr('data-default', $(this).width());
$(this).animate({width: 300}, 'slow');
$(this).parent().addClass('cooling');
}
}).blur(function(){
var w = $(this).attr('data-default');
$(this).animate({
width: w
}, 'slow');
$(this).parent().removeClass('cooling');
});
谢谢。
I have a function that works perfectly if you want to expand an input type=text
with more than 20 characters. My problem is, how to apply this function for disabled inputs? To better understand the behavior of my function check my example on fiddle:
http://jsfiddle.net/DCjYA/168/
$('input[type!="submit"]').focus(function(){
if ($(this).val().length > 20) {
$(this).attr('data-default', $(this).width());
$(this).animate({width: 300}, 'slow');
$(this).parent().addClass('cooling');
}
}).blur(function(){
var w = $(this).attr('data-default');
$(this).animate({
width: w
}, 'slow');
$(this).parent().removeClass('cooling');
});
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Daniel 所说,
focus
和blur
事件不适用于disabled
input
。然后,出于此目的,可以使用hover、mouseenter 或 mouseover、mouseleave 或 mouseout
事件,但我找不到它的工作原理,但我确实找到了mousemove
的扩展它。你可以使用它来解决你的问题。
小提琴:http://jsfiddle.net/raj_er04/DCjYA/174/
As Daniel said the
focus
andblur
event will not work with thedisabled
input
. Then for this purpose,hover, mouseenter or mouseover, mouseleave or mouseout
are the events can be used but i could not find it working but i do foundmousemove
forexpanding
it. you can use it it it solve your problem.fiddle : http://jsfiddle.net/raj_er04/DCjYA/174/
由于您无法聚焦禁用的元素,因此您应该为此构建一个解决方法。或者为此使用另一个函数?
编辑:这可能对您有帮助:禁用输入上的事件
Since you can't get to focus an disabled element you should build a workaround for this. Or use another function for this?
EDIT: Probably this could be helpful for you: Event on a disabled input