jQuery | focusin()及其示例

这个 聚焦素() 是jQuery中的一个内置方法,用于获得对所选元素的关注。 语法:

null
$(selector).focusin(function);

参数: 它接受一个可选参数“function”,该参数可以聚焦于选定的元素。 返回值: 它返回获得焦点的选定元素。 显示focusin()方法工作的jQuery代码: 代码#1: 在下面的代码中,传递参数函数。

html

< html >
< head >
< script
</ script >
<!-- jQuery code to show the working of this method -->
< script >
$(document).ready(function() {
$("div").focusin(function() {
$(this).css("background-color", "green");
});
});
</ script >
< style >
div {
border: 2px solid black;
width: 50%;
padding: 20px;
}
input {
padding: 5px;
margin: 10px;
}
</ style >
</ head >
< body >
<!-- click inside the field focusin will take place -->
< div >
Enter name:
< input type = "text" >
< br >
</ div >
</ body >
</ html >


输出: 在单击输入字段内部之前-

图片[1]-jQuery | focusin()及其示例-yiteyi-C++库

单击输入字段内部后,focusin方法将生效-

图片[2]-jQuery | focusin()及其示例-yiteyi-C++库

代码#2: 在下面的代码中,没有传递任何参数。

html

< html >
< head >
< script
</ script >
<!-- jQuery code to show the working of this method -->
< script >
$(document).ready(function() {
$("#foc").click(function() {
$(this).focusin().css("background-color", "lightgreen");
});
});
</ script >
< style >
div {
border: 2px solid black;
width: 50%;
padding: 20px;
}
input {
padding: 5px;
margin: 10px;
}
</ style >
</ head >
< body >
<!-- click inside the field focusin will take place and
background color becomes change -->
< div >
Enter name:
< input id = "foc" type = "text" >
< br >
</ div >
</ body >
</ html >


输出: 在单击输入字段内部之前-

图片[3]-jQuery | focusin()及其示例-yiteyi-C++库

单击输入字段内部后,focusin方法将生效-

图片[4]-jQuery | focusin()及其示例-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享