Javascript 如果我的第三方软件不允许/read<;,我如何运行querySelectorAll;!DOCTYPE>;标签?
我正在开发一个网页,需要集成到我的第三方软件,并输出到HTML网页。但是我的软件不允许也不允许读取doctype。如何在不使用doctype的情况下重新编写此代码Javascript 如果我的第三方软件不允许/read<;,我如何运行querySelectorAll;!DOCTYPE>;标签?,javascript,html,doctype,Javascript,Html,Doctype,我正在开发一个网页,需要集成到我的第三方软件,并输出到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 任何帮助都将不胜感激。谢谢 下面是简单的代码 浏览器:INTERNET EXPLORER 8 JS: fun
note that my problem is not with the codes, but how to remake the codes for them to
work without the DOCTYPE tag
任何帮助都将不胜感激。谢谢
下面是简单的代码
浏览器:INTERNET EXPLORER 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";
}
}
}
函数myFunctionClass(){
var mo=document.querySelectorAll(“.displayBlockClass”);
var getYr=document.getElementById(“date1Year”);
var-m;
对于(m=0;m
如果旧版本的IE不支持中的文档。querySelectorAll
,并且文档开头不能有DOCTYPE
,则需要使用一些polyfill。似乎有一个简单的polyfill可以完成这项工作:
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
之前执行此操作。如果浏览器支持,则无需“读取doctype”测试。如果浏览器不支持此功能,您将需要polyfill。看一看:谢谢杰夫,我怎样才能用你给我的代码重新编写我当前的js?很抱歉,我不熟悉Javascript。