2011-07-27 39 views
0

我們在網頁中有一個文本框,用於修改IP地址。編輯其中的內容後,文本框樣式將更改爲第二個框。我怎樣才能改變風格回到第一個文本框的風格?我們在客戶端使用JavaScript。 Web客戶端是Internet Explorer 7中文本框樣式問題

enter image description here

在ASP頁面的代碼片段它創建文本框下面

<td style="height: 27px"><input type="text" id="txtIpAddressHost" name="txtIpAddressHost" value="" onchange="ValidateParameter(this);" onkeydown="this.style.backgroundColor='white'" disabled="disabled" maxlength="15" /></td> 

的HTML之前給出的變化下面給出

按鍵時

<input type="text" onkeydown="this.style.backgroundColor='white'" onchange="Validate(this);" maxlength="10" value="-30.000000" name="txtCoolSetPointCkt1" id="txtCoolSetPointCkt1"> 

之前按鍵時

<input type="text" onkeydown="this.style.backgroundColor='white'" onchange="Validate(this);" maxlength="10" value="-30.000000" name="txtCoolSetPointCkt1" id="txtCoolSetPointCkt1" style="background-color: white;"> 

CSS改變

css change 
{ 

    background-color: white; 

} 
+0

您是否使用CSS來設置頁面的樣式?它如何改變?該字段的名稱是否發生更改,因此它使用的是CSS樣式?它是否也發生在其他瀏覽器上?有問題的HTML代碼片斷將會很有用。 – xyzjace

回答

1

與CSS 2之後,你可以只用CSS實現這一目標。讓我們假設文本框有類ip-box。

input.ip-box { border:1px solid #333; } 
    //and when the input box has focus repeat the above rule 
    input.ip-box:focus { border:1px solid #333; } 

但ie7不支持這個僞類。在這種情況下,你可以使用JavaScript像

<input type="text" value="10.0.0.88" onfocus="javascript:this.style.border='1px solid #333' "/> 
+0

應該提及onblur事件以及 – Ben

+0

這只是給出這個想法的片段。重點是始終應用​​相同的風格。即默認,onfocus和是的,你也可以添加onblur。 – Ehtesham