作者arrack (Arrack Tseng)
看板Web_Design
標題Re: [問題] 文字方塊的焦點
時間Sat Oct 24 17:20:32 2009
※ 引述《l8 (+12=30)》之銘言:
: 請問有沒有什麼方法 可以讓使用者在載入網頁的時候
: 就直接將焦點設定在文字方塊上 (就是那個閃爍的 │ )
: 不必還要用滑鼠特地去文字方塊上點一下才能輸入文字
: 類似像這樣↓
: ┌──────┐
: ││ │
: └──────┘
<input type="text" name="InputFocus" id="InputFocus" />
簡易作法
<script type="text/javascript">
document.getElementById('InputFocus').focus();
</script>
保險作法,避免跟其他的衝突
<script type="text/javascript">
var onload_before = window.onload || function () {};
window.onload = function ()
{
onload_before();
document.getElementById('InputFocus').focus();
}
</script>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
推 l8:<body onload="document.getElementById('xxx').focus();"> 10/24 17:22
→ l8:我後來用這樣成功的 感謝你 10/24 17:22
→ arrack:這樣也是可以XD,就每個人習慣不同 10/24 17:24
※ 編輯: arrack 來自: 61.64.103.76 (10/24 19:58)