禁用元素的调用函数

发布于 2024-12-28 21:31:06 字数 651 浏览 4 评论 0原文

如果您想扩展超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦断已成空 2025-01-04 21:31:06

正如 Daniel 所说,focusblur 事件不适用于 disabled input。然后,出于此目的,可以使用 hover、mouseenter 或 mouseover、mouseleave 或 mouseout 事件,但我找不到它的工作原理,但我确实找到了 mousemove扩展它。你可以使用它来解决你的问题。

$('input:disabled').mousemove(function(){
      if ($(this).val().length > 20) {
       $(this).attr('data-default', $(this).width());
       $(this).animate({width: 300}, 'slow');
       $(this).parent().addClass('cooling');
      }
});

小提琴:http://jsfiddle.net/raj_er04/DCjYA/174/

As Daniel said the focus and blur event will not work with the disabled 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 found mousemove for expanding it. you can use it it it solve your problem.

$('input:disabled').mousemove(function(){
      if ($(this).val().length > 20) {
       $(this).attr('data-default', $(this).width());
       $(this).animate({width: 300}, 'slow');
       $(this).parent().addClass('cooling');
      }
});

fiddle : http://jsfiddle.net/raj_er04/DCjYA/174/

娇女薄笑 2025-01-04 21:31:06

由于您无法聚焦禁用的元素,因此您应该为此构建一个解决方法。或者为此使用另一个函数?

编辑:这可能对您有帮助:禁用输入上的事件

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文