我寫過一些代碼,可以讓我在輸入表單上顯示一些灰色的文本,當用戶關注它時,文本會消失並變得沒有任何意義,如果有道理...onfocus&onblur無法在IE中工作
function editableAlt (elem, colour1, colour2) {
var elem = document.getElementById(elem);
elem.onfocus = function() {
if(this.value == this.defaultValue) {
this.value = ""; // remove the default text, so the user can enter their own
this.style.color = "#" + colour1; // change the text colour
}
};
elem.onblur = function() {
if(this.value == '') {
this.value = this.defaultValue; // user left it blank? revert back to the default text
this.style.color = "#" + colour2; // and change the colour back too
}
}
}
這是工作在大多數頁面上,但在一個由於某種原因onfocus和的onblur是不工作 - 如果我改變它例如以它的onclick觸發沒有問題。
還有什麼我可以嘗試嗎? :(我使用JQuery,但除去這似乎並沒有在所有實現它。
乾杯
作品在我的IE6千恩萬謝:http://jsbin.com/aduni你做。東西在你的代碼的其他錯誤別處 – 2009-09-25 15:12:08
謝謝,我甚至試過這種使用jQuery無濟於事: \t \t如果($( 「#Absence_Hours」)長度> 0){ \t \t \t $此= $(本); //緩存變量 \t \t \t $ this.focus(函數(){ \t \t \t \t警報( '試驗'); \t \t \t}); \t \t} 改變焦點()點擊()工作正常,但... – Nick 2009-09-28 09:42:09