2012-01-23 52 views
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'); 
}); 

謝謝。

回答

0

正如丹尼爾說,focusblur事件不會與disabledinput工作。然後爲此目的,hover, mouseenter or mouseover, mouseleave or mouseout是事件可以使用,但我找不到它的工作,但我發現mousemoveexpanding它。你可以用它來解決你的問題。

$('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/

+0

在IE :( – mcmwhfy

+0

不工作,嘗試$(「輸入[禁用]')..它會在所有 –

+0

工作不,它不工作在IE8上:((檢查小提琴 – mcmwhfy

0

由於您無法專注于禁用的元素,因此應該爲此構建解決方法。或者使用其他功能呢?

編輯:也許這可能是對你有所幫助:Event on a disabled input

+0

以及如何整合這在我的功能:不是真的想使用其他功能:(( – mcmwhfy