为禁用的元素调用函数

Call function for disabled elements

本文关键字:调用 函数 元素      更新时间:2023-09-26

如果您想扩展一个包含20个以上字符的input type=text,我有一个函数可以很好地工作。我的问题是,如何将此功能应用于禁用的输入?为了更好地理解我的函数的行为,请查看我在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');
});

谢谢。

正如Daniel所说,focusblur事件将不适用于disabled input。然后为了这个目的,hover, mouseenter or mouseover, mouseleave or mouseout是可以使用的事件,但我找不到它工作,但我确实为expanding找到了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/

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

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