對於在IE 9中顯示佔位符,我使用了以下腳本 它工作正常,但在刷新後的某些頁面中只有其工作。placeholder和ie9
var _debug = false;
var _placeholderSupport = function() {
var t = document.createElement("input");
t.type = "text";
return (typeof t.placeholder !== "undefined");
}();
window.onload = function() {
var arrInputs = document.getElementsByTagName("input");
for (var i = 0; i < arrInputs.length; i++) {
var curInput = arrInputs[i];
if (!curInput.type || curInput.type == "" || curInput.type == "text")
HandlePlaceholder(curInput);
}
};
function HandlePlaceholder(oTextbox) {
if (!_placeholderSupport) {
var curPlaceholder = oTextbox.getAttribute("placeholder");
if (curPlaceholder && curPlaceholder.length > 0) {
Debug("Placeholder found for input box '" + oTextbox.name + "': " + curPlaceholder);
oTextbox.value = curPlaceholder;
oTextbox.setAttribute("old_color", oTextbox.style.color);
oTextbox.style.color = "$placeholder";
oTextbox.onfocus = function() {
Debug("input box '" + this.name + "' focus");
this.style.color = this.getAttribute("old_color");
if (this.value === curPlaceholder)
this.value = "";
};
oTextbox.onblur = function() {
Debug("input box '" + this.name + "' blur");
if (this.value === "") {
this.style.color = "$placeholder";
this.value = curPlaceholder;
}
};
}
else {
Debug("input box '" + oTextbox.name + "' does not have placeholder attribute");
}
}
else {
Debug("browser has native support for placeholder");
}
}
function Debug(msg) {
if (typeof _debug !== "undefined" && _debug) {
var oConsole = document.getElementById("Console");
if (!oConsole) {
oConsole = document.createElement("div");
oConsole.id = "Console";
document.body.appendChild(oConsole);
}
oConsole.innerHTML += msg + "<br />";
}
}
問題和預期產出是什麼? –
'只有它的工作.'沒有足夠詳細的理解,不知道是什麼意思 – charlietfl
例如,一些divs只顯示一些按鈕後才顯示。在這種情況下頁面不加載.Plcaeholder也不顯示,bt一次我刷新頁面,然後它即將到來 – Prashobh