1

検索ボックスにデフォルト値の色とフォントを追加する方法。

<input type="text" name="q" value="Enter your keywords here"    
onfocus="if (this.value == 'Enter your keywords here') {this.value = '';}" onblur="if (this.value   == '') {this.value = 'Enter your keywords here';}"
onwebkitspeechchange = "this.value = this.value.replace('Enter your keywords here','')";
x-webkit-speech style="left:9px;top:4px;position:relative;background-color:#fafafa;border:1px     solid;color:#333;font-size:1.4em;width:400px;height:28px"; />
4

2 に答える 2

3

入力ボックスのデフォルトのスタイルを設定してから、次のようにonfocusおよびonblurイベントの色を変更できます。

<input type="text" name="q" value="Enter your keywords here"    
    onfocus="if (this.value == 'Enter your keywords here') {
        this.value = ''; 
        this.style.color = '#000';
    }" 
    onblur="if (this.value == '') {
        this.value = 'Enter your keywords here'; 
        this.style.color = '#CCC';
    }"
    onwebkitspeechchange = "this.value = this.value.replace('Enter your keywords here','')";
    x-webkit-speech 
    style="left:9px;top:4px;position:relative;background-color:#fafafa;border:1px solid; color:#CCC;font-size:1.4em;width:400px;height:28px"; 
/>

また、コードをすっきりと見せるために、このイベントコードを別のスクリプトに入れることを検討する必要があります。

このフィドルを見て、少しクリーンなコードを探すこともできます。 http://jsfiddle.net/MXpSw/

于 2012-06-02T06:10:00.063 に答える
0

スタイルで色を変更します...

<input type="text" name="q" value="Enter your keywords here"    
onfocus="if (this.value == 'Enter your keywords here') {this.value = '';}" onblur="if (this.value   == '') {this.value = 'Enter your keywords here';}"
onwebkitspeechchange = "this.value = this.value.replace('Enter your keywords here','')";
x-webkit-speech style="left:9px;top:4px;position:relative;background-color:#fafafa;border:1px solid     #555;color:#aaa;font-size:1.4em;width:400px;height:28px"; />
于 2012-06-02T06:12:25.493 に答える