我正在开发一个需要集成到我的第三方软件并输出到HTML网页的网页。但我的软件不允许也不读 DOCTYPE 。如何在不使用DOCTYPE的情况下重新编写此代码。
note that my problem is not with the codes, but how to remake the codes for them to
work without the DOCTYPE tag
非常感谢任何帮助。感谢。
这是简单的代码。
浏览器:互联网探索者8
JS:
function myFunctionClass(){
var mo = document.querySelectorAll(".displayBlockClass");
var getYr = document.getElementById("date1Year");
var m;
for (m = 0; m < mo.length; m++){
if(getYr.value == "2001" || getYr.value == "2003" || getYr.value == "2005"){
mo[m].style.display = "";
}
else{
mo[m].style.display = "none";
}
}
}
答案 0 :(得分:1)
如果旧版本的IE在quirks mode中缺少对document.querySelectorAll
的支持而您在文档的开头没有DOCTYPE
,则需要使用一些填充。似乎有一个简单的polyfill qsa-polyfill-ie7.js可以完成这项任务:
if (!document.querySelectorAll) {
document.querySelectorAll = function(selector) {
var doc = document,
head = doc.documentElement.firstChild,
styleTag = doc.createElement('STYLE');
head.appendChild(styleTag);
doc.__qsaels = [];
styleTag.styleSheet.cssText = selector +
"{x:expression(document.__qsaels.push(this))}";
window.scrollBy(0, 0);
return doc.__qsaels;
}
}
在第一次调用document.querySelectorAll