2009-11-24 76 views
2

我有一個文本輸入字段,其中包含一些淺灰色字體的示例文本,當用戶單擊字段輸入時將清除該字體。當發生這種情況時,我還想將字體顏色更改爲黑色,以便用戶更容易閱讀他們正在輸入的內容。這是我目前使用的:文本輸入字段CSS樣式

<input type="text" name="q" value="Enter keywords" onfocus="if(this.value == 'Enter keywords') {this.value = '';}" style="width:630px;font-size:14px;color:#ADADAD;border:1px solid #ADADAD;}"> 

這是可能的使用CSS,如果是的話如何更新我的文本字段來實現這一點。在此先感謝您的幫助!

回答

1

嘗試

<input type="text" name="q" value="Enter keywords" onfocus="if(this.value == 'Enter keywords') {this.value = ''; this.style.color = 'black';}" style="width:630px;font-size:14px;color:#ADADAD;border:1px solid #ADADAD;}"> 
+0

@Nick - 像魅力一樣工作。感謝您及時的回覆! – 2009-11-24 20:04:22

0

簡單的辦法是:

<input type="text" name="q" value="Enter keywords" onfocus="if(this.value == 'Enter keywords') {this.value = '';this.style.color = '#000000';} else {this.style.color = '#000000';}" style="width:630px;font-size:14px;color:#ADADAD;border:1px solid #ADADAD;}"> 

但是,如果你在jQuery的有興趣,然後......你會魔法。

0

在現場的焦點處理器,嘗試this.style.color = 「#000000」;