IE8下获取background-position为undefined的解决办法

直接上code

<script type="text/javascript">
        $(function () {
            $('.spanfolder').click(function () {
                if(typeof($(this).siblings('.divfolder').css('background-position')) != 'undefined')//IE8下为undefined
                {
                    if ($(this).siblings('.divfolder').css('background-position') == "-80px -3px") {
                        $(this).siblings('.divfolder').css('background-position', '-64px -25px');
                        $(this).css('background-image', 'url(images/folder.gif)');
                    }
                    else {
                        $(this).siblings('.divfolder').css('background-position', '-80px -3px');
                        $(this).css('background-image', 'url(images/folder-closed.gif)');
                    }
                }
                else
                {
                    if ($(this).siblings('.divfolder').css('background-positionX') == "-80px") {
                        $(this).siblings('.divfolder').css('background-position', '-64px -25px');
                        $(this).css('background-image', 'url(images/folder.gif)');
                    }
                    else {
                        $(this).siblings('.divfolder').css('background-position', '-80px -3px');
                        $(this).css('background-image', 'url(images/folder-closed.gif)');
                    }
                }
                $(this).siblings('ul').slideToggle('fast');
            });
           
            });

    </script>
posted @ 2012-07-28 23:44  Mr.H  阅读(1376)  评论(0编辑  收藏  举报