這是行不通的,因爲onmouseover
在大多數瀏覽器中不會禁用禁用輸入。 (Opera是一個例外,IE通常不會,除非你用拖動操作來欺騙它。)
在任何情況下,它聽起來都像是一個非常奇怪和用戶不友好的詭計。 爲什麼選擇要禁用它嗎?如果它在嘗試與之交互時變爲非禁用狀態,那麼它似乎沒有任何意義(但存在大量的可訪問性缺陷)。
如果它只是一個造型的東西,然後使用樣式:
<style type="text/css">
.weirdinput { color: silver; }
.weirdinput:hover, .weirdinput:focus { color: black; }
</style>
<input class="weirdinput" value="smth" />
然而,IE < 8不支持:focus
,和IE < 7不支持非鏈接:hover
,因此,如果您需要它的工作,你將不得不添加一些腳本,例如。例如:
<style type="text/css">
.weirdinput { color: silver; }
.weirdinput:hover, .weirdinput:focus, .weirdhover, .weirdfocus { color: black; }
</style>
<input class="weirdinput" value="smth" />
<!--[if lt IE 8]><script type="text/javascript">(function() {
// Fix focus/hover for IE on all inputs with class 'weirdinput'
//
var inputs= document.getElementsByTagName('input');
for (var i= 0; i<inputs.length; i++) {
var input= inputs[i];
if (input.className.indexOf('weirdinput')!==-1) {
input.onmouseover= mouseover;
input.onmouseout= mouseout;
input.onfocus= focus;
input.onblur= blur;
}
}
function mouseover() {
this.className+= ' weirdhover';
}
function mouseout() {
this.className= this.className.replace(' weirdhover', '');
}
function focus() {
this.className+= ' weirdfocus';
}
function blur() {
this.className= this.className.replace(' weirdfocus', '');
}
})();</script><![endif]-->
這聽起來像一個非常奇怪的用戶體驗,如果你不介意我的話。首先,這意味着您完全禁用鍵盤訪問該字段。我們的鍵盤類型不會那麼喜歡,可訪問性軟件也可能會遇到這種情況。 – 2010-05-26 13:09:53
你能告訴我們更多關於你爲什麼要這樣的行爲嗎? – 2010-05-26 13:13:46
我同意T.J.對此,我很少在網頁上觸摸我的鼠標。 – CharlesLeaf 2010-05-26 13:14:07