如何在jquery中将onfocus事件添加到自定义创建的控件?

时间:2013-07-23 19:05:29

标签: jquery custom-controls

我有一个使用jquery库创建的自定义创建的组合框控件,其中我将文本框包裹在下拉控件上,这样每当我使用这个组合框控件时,我实际上都会调用它的对象。现在我想将常用文本框的onfocus函数挂钩到此自定义控件。那怎么能这样呢?相关答案非常感谢&欢迎来自我的心底!

1 个答案:

答案 0 :(得分:0)

请查看演示 http://jsfiddle.net/z2y6T/

<html>
<head>
  <style>span {display:none;}</style>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
  <p><input type="text" /> <span>focus fire</span></p>
<p><input type="password" /> <span>focus fire</span></p>
<script>
$("input").focus(function () {
  $(this).next("span").css('display','inline').fadeOut(1000);
});
</script>

</body>
</html>

jQuery Focus

  

将事件处理程序绑定到“焦点”JavaScript事件,或触发该事件   元素上的事件

更多信息:http://api.jquery.com/focus/