Rozważam dynamiczne ustawianie atrybutu ID elementów wejściowych HTML, które są dynamicznie tworzone w mojej aplikacji.dynamicznie ustawiając atrybut id elementu wejściowego w IE: alternatywa dla metody setAttribute
Moja implementacja działa dobrze z metodą setAttribute w przeglądarce Firefox. Wszelkie pomysły i rozwiązania dotyczące działającej implementacji w IE będą mile widziane.
var hiddenInput = document.createElement("input");
hiddenInput.setAttribute("id", "uniqueIdentifier");
hiddenInput.setAttribute("type", "hidden");
hiddenInput.setAttribute("value", ID);
hiddenInput.setAttribute("class", "ListItem");
I zmodyfikowane niektóre przykładowy kod z blogów dotyczących tego problemu, które sugerują następujący workround. Znowu nieco Firefox działa dobrze, ale nieco IE doens't
var hiddenInput = null;
try {
hiddenInput = document.createElement('<input name=\''+"hiddenInputName"+'\' />');
hiddenInput.id = "uniqueIdentifier";
//alert(document.getElementById("uniqueIdentifier"));
hiddenInput.type = "hidden";
} catch (e) { }
if (!hiddenInput || !hiddenInput.name) { // Not in IE, then
var hiddenInput = document.createElement("input");
hiddenInput.setAttribute("id", "uniqueIdentifier");
hiddenInput.setAttribute("type", "hidden");
}
Cheers.
W której wersji IE testujesz? – gor
Internet Explorer 8 – Terman
Co dokładnie nie działa? Czy jest komunikat o błędzie? Co idzie źle? –