divがクリックされたときに入力要素にフォーカスしたい。
私のHTMLは次のようになります。
<div class="placeholder_input">
<input type="text" id="username" maxlength="100" />
<div class="placeholder_container">
<div class="placeholder">username</div>
</div>
</div>
そして、私のスクリプトは次のとおりです。
$("#username").focus(function() {
$(this).next().hide();
});
$(".placeholder_input").mousedown(function() {
$(this).children(":first").focus();
});
テキスト ボックスをクリックすると、プレースホルダー テキストは正しく消えますが、点滅するカーソルがテキスト ボックスに表示されません。(そして、テキストボックスにテキストを入力できません)
mousedown
イベント ハンドラー内では、$(this).children(":first")
式によって正しい入力要素が選択されるため、呼び出しが機能しない理由がfocus()
わかりません。