有没有任何库可以在IE8中运行一些HTML5输入类型?例如range。
Points: <input type="range" name="points" min="1" max="10">
<input type="submit" value="send">
有没有任何库可以在IE8中运行一些HTML5输入类型?例如range。
Points: <input type="range" name="points" min="1" max="10">
<input type="submit" value="send">
IE8不支持<input type="range">
。在旧版浏览器中实现此功能的最无缝方法是检测支持并在需要时使用"polyfills"。Polyfill旨在为旧版浏览器添加支持,通常使用一些JavaScript来模拟本地行为。
这个页面有一个很好的polyfill列表。(而Modernizr是检测此类事物支持的好方法)您将在该列表中找到各种输入类型的polyfills。
Ie8将把所有“html5”输入类型呈现为文本。但是,您可以使用JavaScript来针对这些类型进行定位,例如:
$('[type=range]').slider() //insert your favorite library here...
我知道这段代码没有标记为jQuery,但我认为示例仍然足够清晰。
我想起了Chrome Frame,这是谷歌的一个项目,将Chrome引擎嵌入到Trident中。
网址:http://www.google.com/chromeframe
我自己从未尝试过。当浏览器遇到问题时,我们会修复它或找到解决方法。我不太喜欢使用插件,特别是从管理角度考虑。
另一个选择是使用modernizr库来检测浏览器的能力,并找到相应的解决方法。总有一些巧妙的方法可以解决问题。使用html5 shiv可能是解决IE8问题的一种方法。以上是我处理IE8问题时喜欢采用的第二个选项。祝好!
<input name="range" id="range" type="range" min="1" max="10" />
<!--[if lt IE 10]>
<div id="range_ie" style="position:relative; width:255px; height:15px; font-size:0px; cursor:default" onselectstart="return false">
<div style="position:absolute; left:0px; top:5px; width:100%; height:30%; border-left:1px solid gray; border-top:1px solid gray; border-right:1px solid white; border-bottom:1px solid white; background:silver"></div>
<div id="slider" style="position:absolute; left:0px; top:0px; width:5px; height:100%; border:1px solid gray; background:#EBEBEB; font-size:15px" onmousedown="document.onmousemove=changevalue"> </div>
</div>
<script type="text/javascript">
//Hide the <input> element, otherwise older versions of IE will just display it as a text input
document.getElementById("range").style.display = "none";
//If the user releases the mouse after changing the value of the range input, it should stop changing
document.body.onmouseup = function() {
document.onmousemove = function(){};
};
function changevalue(e) {
//Get the value of the input from the position of the cursor
range.value = ((navigator.appName.substring(0, 3) == "Net") ? e.pageX : event.x) * (range.max - range.min) / (document.getElementById("range_ie").style.width.substring(0, document.getElementById("range_ie").style.width.search("px"))) + Number(range.min);
//Check that the value isn't out of bounds
if (Number(range.value) > Number(range.max)) {
range.value = range.max;
}
if (Number(range.value) < Number(range.min)) {
range.value = range.min;
}
//Move the slider to its new position
document.getElementById("slider").style.left = (range.value - range.min) * Number(document.getElementById("range_ie").style.width.substring(0, document.getElementById("range_ie").style.width.search("px"))) / (Number(range.max) - Number(range.min)) + "px";
}
//If we click on the slider just like that, it should move
document.getElementById("range_ie").onclick = changevalue;
</script>
<![endif]-->