輸入框是表單中最常見的元素之一。以下整理幾個實用的輸入框技巧,包含透明背景、滑鼠移入變色、邊框效果、自動延展與序號式輸入等。
<input style="background:transparent; border:1px solid #ffffff;" />
可使用 CSS :hover,或在舊寫法中透過 onmouseover 與 onmouseout 切換樣式。
<input onmouseover="this.style.backgroundColor='plum';"
onmouseout="this.style.backgroundColor='#ffffff';" />
<input style="border:0; border-bottom:1px solid black; background:transparent;" />
序號輸入框通常由多個 input 組成,每格限制字元數,並在輸入完成後自動跳到下一格。舊寫法會使用 maxlength 與 focus() 切換。
這些技巧在舊專案中很常見,但新專案建議優先使用標準 CSS 與 JavaScript,避免依賴已淘汰的 IE expression。