JS不适用于IE

时间:2012-03-15 16:12:10

标签: javascript internet-explorer

我尝试开发一个页面但不适用于IE。

这是实际页面:

http://portal.sinemalar.com/tv/vestel/v1/artist/48029/1/1/1/2/

您可以使用向上和向下箭头键。它适用于Google Chrome和Firefox但不适用于IE

这是代码:

<script type="text/javascript">
    {literal}
    document.onload = function () {
        MousePlayClick();
    }
    {/literal}
</script>

<script type="text/javascript">
    {literal}
    function artistKeyPress(evt) {
        switch (evt.keyCode) {
            case KEYS.UP:
                if ($page > 1) {
                    $page--;
                    window.location.href = baseUrl + 'artist/' + $movieId + '/' + $vPage + '/' + $yPage + '/' + $slot + '/' + $page + '/';
                }
                break;
            case KEYS.DOWN:
                $page++;
                window.location.href = baseUrl + 'artist/' + $movieId + '/' + $vPage + '/' + $yPage + '/' + $slot + '/' + $page + '/';
                break;
            case KEYS.RED:
                window.location.href = baseUrl + 'detail/' + $movieId + '/' + $vPage + '/' + $yPage + '/' + $slot + '/';
                break;
        }
    }
    {/literal}
</script>

<script>    

    var $slot = {$cursor};
    var $vPage = {$vPage};
    var $yPage = {$yPage};
    var $page = {$page};
    var $movieId = {$movieId};
    var $mp4Link = '{$mp4Link}';
    {literal}        
    document.onkeydown = function(evt) 
    {
        artistKeyPress(evt);
    }
    {/literal}
</script>
<div class="main_content">
    <a href="{$portalPath}vestel/v1/artist/{$movieId}/{$prevPage}"><div class="yorum_yukari_ok ortala"></div></a>
    {foreach value=artist key=key from=$artists}
    <div class="yatay_kutu{if $key%2==0}_secili{/if}">
        <div class="yk_foto_cont_s">
            <img src="{$artist.picture}" height="132px" />
        </div>
        <div class="yorum_a">
            <h2 class="bold">{$artist.nameSurname}<span class="sag">Puan:{$artist.rating}/10</span></h2>
            {$artist.bio}
        </div>
    </div>
    {/foreach}
    <a href="{$portalPath}vestel/v1/artist/{$movieId}/{$nextPage}"><div class="yorum_asagi_ok ortala"></div></a>
</div>

可能是什么原因?

2 个答案:

答案 0 :(得分:2)

Internet Explorer不理解evt.keyCode,而是尝试:

var keyCode = (window.event) ? window.event.which : evt.keyCode;

switch(keyCode){
   //...
}

答案 1 :(得分:1)

function artistKeyPress(evt) {
    evt = evt || window.event;  //handles IE which uses window.event for the details
    var keyCode = evt.keyCode || evt.which;  //handles cross browser with what key was pressed
    switch (keyCode) {