轉自:伊沙熊的學習筆記本:【備忘】JavaScript: 文字欄位浮水印 - 樂多日誌:
javasciprt程式碼:
<input name="textfield" type="text" value="浮水印自訂文字" style="color: #AAAAAA;" onfocus="if (this.value == '浮水印自訂文字') {this.value = ''; this.style.color='#333333'}" onblur="if (this.value == '') {this.value = '浮水印自訂文字'; this.style.color='#AAAAAA'}" >
程式碼(AS3):
02 | txtfield1.addEventListener (FocusEvent.FOCUS_OUT, addTextDefault); |
03 | txtfield1.addEventListener (FocusEvent.FOCUS_IN, removeTextDefault); |
05 | var default_tf = txtfield1.getStyle ( "textFormat" ); |
07 | function addTextDefault (e) { |
08 | if (e.currentTarget.text == "" ) { |
09 | e.currentTarget.setStyle ( "textFormat" , new TextFormat( null , null , 0xAAAAAA )); |
10 | e.currentTarget.text = "←請輸入資料" ; |
13 | function removeTextDefault (e) { |
14 | if (e.currentTarget.text == "←請輸入資料" ) { |
15 | e.currentTarget.setStyle ( "textFormat" , default_tf); |
16 | e.currentTarget.text = "" ; |
19 | addTextDefault ({currentTarget:txtfield1}); |
很短的程式碼, setStyle函式是用來設定組件的樣式
沒有留言:
張貼留言