「jQuery入門」focusin()で親、子要素をフォーカスするサンプル

2021年2月19日

書式
$('セレクター名’).focusin(function(){//処理コード}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>focus()select()のサンプル</title>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<div id="cft">
<input type="text" value="testuser" name="username">
</div>
<script>
$('#cft').focusin(function() {
console.log('divがフォーカスされた');
});
</script>
</body>
</html>
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>focus()とselect()のサンプル</title> <script src="https://code.jquery.com/jquery-3.5.0.js"></script> </head> <body> <div id="cft"> <input type="text" value="testuser" name="username"> </div> <script> $('#cft').focusin(function() { console.log('divがフォーカスされた'); }); </script> </body> </html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>focus()とselect()のサンプル</title>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<div id="cft">
    <input type="text" value="testuser" name="username">
</div>
<script>
 $('#cft').focusin(function() {
    console.log('divがフォーカスされた');
  });
</script>
</body>
</html>

 

jQuery

Posted by arkgame