为禁用的元素调用函数
Call function for disabled elements
如果您想扩展一个包含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所说,focus
和blur
事件将不适用于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/
由于无法聚焦禁用的元素,因此应该为此构建一个变通方法。或者为此使用另一个函数?
编辑:这可能对您有帮助:禁用输入的事件
相关文章:
- 如何从模块链中调用函数.导出到节点中
- 调用函数内部的函数
- 在javascript中调用c函数
- DropDownListFor赢得't在更改时调用函数
- Javascript页面调用函数
- 在动画结束之前调用函数
- 允许父窗口在其不同域的子iframe上调用函数
- 运行Infinite Scroll后调用函数时出现问题
- JavaScript:在调用函数的文本输入上按enter键
- 使用大括号和不使用bracs调用函数的区别
- javascript在事件上调用函数
- 从index.html调用函数,该函数无限循环
- 从带参数的字符串变量调用函数中的函数
- 为什么 JS 不在滚动时调用函数
- 是否可以在不更改上下文的情况下调用函数.apply
- 如何在ES6类中使用参数调用函数
- AngularJS:调用函数时编号不更新
- JavaScript中的立即调用函数表达式(IIFE)-传递jQuery
- 在JavaScript中调用函数时自定义此选项
- 调用函数中声明的变量