我有這種情況 - 在我們的ASPX站點上,使用DEVExpress,只在IE 8(原始的IE 8模式不是IE 9)在登錄頁面上我們經常出現一個錯誤:使用ASPX和DEVExpress覆蓋IE 8上的JS focus()方法...
Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
所以 - 我研究並發現某些東西試圖集中某些看不見的東西。所以我嘗試了這個解決方案 - 重寫focus()方法。下面是一個簡短的HTML頁面示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AccuLynx</title>
<script type="text/javascript">
HTMLInputElement.prototype.focusCpy = HTMLInputElement.prototype.focus;
HTMLInputElement.prototype.focus = function() {
if(this.style.display != 'none' && this.style.visibility != 'hidden' && !this.disabled && this.type != 'hidden') {
HTMLInputElement.prototype.focusCpy.apply(this, arguments);
}
}
</script>
</head>
<body>
<input type="submit" id="my_link" style="display:none;" value="dfsdfd" />
<script type="text/javascript">
document.getElementById('my_link').focus();
</script>
</body>
</html>
然後在測試頁上一切看起來不錯,但在真實網站上 - 不是。
JS代碼是第一個被執行的東西之一 - 在第二個JS文件(第一個是JQuery插件)的開頭 - 但它不起作用。
任何意見表示讚賞。
我會先嚐試找到發出焦點語句並防止發生這種情況的代碼。如果這是不可能的,你可以嘗試處理錯誤,並且如果將焦點設置爲允許的元素。 –
這是個奇怪的問題。最好聯繫DX並要求他們解決問題。 – Mikhail