2010-12-28 12 views
0

誰かがIEのどのバージョンでもうまくいかない理由が考えられますか?私は要素のフォントファミリを選択するドロップダウン選択メニューを持っています。これは、フォントファミリーを変更するためのjavascript関数を呼び出します。ここでは、HTML ...IEのJavaScriptフォントファミリの問題

<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のフォントファミリを変更する働きがあります。何かご意見は?私は、それはかなり簡単な機能です、私はそれについて行くために他の方法を考えようとしたが、私はかなり固執しています。これを読んだ皆さん、ありがとう!

+0

私は根本的に間違って何かを見ることができません。あなたがそれがうまくいかない場所に絞り込めますか?エラーはありますか? –

+0

奇妙なことに、エラーはスローされません。私はデバッグするためにIE8の開発者ツールを掘り出し、何も得られません。フォントファミリは変更されていません。不思議なこと..... – Hacknightly

答えて

0

コードをデバッグした場合、selector.valueは何も返しません。

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
    <h1 id="liveh1">Some text</h1> 
    <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> 
    <script> 
     function updateh1family() { 
     var selector = document.getElementById('selecth1FontFamily'); 
     var family = selector.options[selector.selectedIndex].value; 
     var h1 = document.getElementById('liveh1') 
     h1.style.fontFamily = family;   
     } 

    </script> 
</body> 
</html> 

JSBin

+0

ああ、ありがとう。デバッグコードの真の意味を理解する必要があると思います。私はそのような騒ぎのように感じる。再度、感謝します。 – Hacknightly