IE 中的 JavaScript 字体系列问题
有人能想到这在任何版本的 IE 中都不起作用的原因吗?我有一个下拉选择菜单,用于选择元素的字体系列,它调用 javascript 函数来更改字体系列。这是 html...
<select id="selecth1FontFamily" name="selectFontFamily" onchange="updateh1family();">
<option> Serif </option>
<option> Arial </option>
<option> Sans-Serif </option>
<option> Tahoma </option>
<option> Verdana </option>
<option> Lucida Sans Unicode </option>
</select>
这是 JavaScript...
function updateh1family() {
var selector = document.getElementById('selecth1FontFamily');
var cssPreviewSpan = document.getElementById('h1FontFamily');
cssPreviewSpan.innerHTML = selector.value;
// also update the CSS preview
var h1 = document.getElementById('liveh1')
h1.style.fontFamily = selector.value;
}
这可以改变每个浏览器中元素的字体系列,除了可怕的 Internet Explorer。有什么想法吗?我的意思是,这是一个相当简单的功能,我试图想出其他方法来实现它,但我几乎陷入困境。感谢所有阅读本文的人!
Can someone think of a reason that this wouldn't work in any version of IE? I have a drop down select menu for choosing the font family of an element, which calls a javascript function to change the font-family. Here is the html...
<select id="selecth1FontFamily" name="selectFontFamily" onchange="updateh1family();">
<option> Serif </option>
<option> Arial </option>
<option> Sans-Serif </option>
<option> Tahoma </option>
<option> Verdana </option>
<option> Lucida Sans Unicode </option>
</select>
And here is the JavaScript...
function updateh1family() {
var selector = document.getElementById('selecth1FontFamily');
var cssPreviewSpan = document.getElementById('h1FontFamily');
cssPreviewSpan.innerHTML = selector.value;
// also update the CSS preview
var h1 = document.getElementById('liveh1')
h1.style.fontFamily = selector.value;
}
This works to change the font family of the element in EVERY browser, minus the dreaded internet explorer. Any thoughts? I mean, it is a fairly straightforward function, I tried to think of other ways to go about it but I'm pretty much stuck. Thank you to all who read this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您调试代码,您会看到selector.value 没有返回任何内容。
JSBin
If you debugged the code you would see that selector.value returns nothing.
JSBin