2012-04-03 32 views
0

我使用一个jQuery插件,自动调整大小来调整我的textarea没能获得

在插件我有这样的事情目前专注元素..

(function($){ 
    $.fn.autoResize = function(options, idToBeShown) { 

    updateSize = function() { 
     //shows the content underneath the textbox with a slidedown effect  
    }, 

    resetSize = function(event) { 
     //Slide up and hide the contents underneath the textarea 
    }, 


    textarea 
    .unbind('.dynSiz') 
    .bind('keyup.dynSiz', updateSize) 
    .bind('keydown.dynSiz', updateSize) 
    .bind('focus',updateSize) //slide's down when focused 
    .bind('focusout',changeSize) //Slide up and hide the contents underneath the textarea 
    .bind('change.dynSiz', updateSize); 



    }); 

我的问题是,当我点击textarea的下方区域textarea的不应该效果基本show而是 当我点击在体内应该向上滑动的任何地方..

所以我做了这个..

resetSize = function(event) { 
//check the current focused element if it is the div area under text do do anything else slideup  
}, 

我不能让当前的焦点内容,

1)document.activeElement返回身体

2)尝试是( “:焦点”);

3)( “:激活”)

没有什么工作...注意我也有加入 '身份证' 的div元素..

回答

0

试试这个:

updateSize()

//process 
$('#divId').addClass('active'); 

resetSize()

if($('#divId').hasClass('active')){ 
    //process 
    $('#divId').removeClass('active'); 
} 
0
$(":input").focus(function() { 

    $(document).click(function(e) { 
     //resetSize; 
    }); 

}); 
+0

每次输入焦点时,是不是将新的点击处理程序绑定到文档? – s4y 2012-04-03 14:14:36

+0

对不起 - 如此习惯做香草javascript - 我更新了点击处理程序,因此它添加了点击方法而不是替换。 – 2012-04-03 17:14:54