否则if语句未在jQuery中注册

Ale*_*lex -3 javascript jquery if-statement

我在jQuery中遇到'if else if'函数的问题.根本没有检测到我的代码的最后两个语句,所以当我希望加载页面时没有任何反应.有人知道这有什么问题吗?

function pageloader() {
    var position = $('#slideInner').css('marginLeft');
    if (position >= '-936px') {
        // load the page contents 
        $('#blogs').load('pagetwo.html #blog');
        // hide the loading box 
        loadoff();
        $('#portfolio').empty();
    }
    else if (position = '-1872px') {
        $('#portfolio').load('pagethree.html #homepage');
        loadoff();
        $('#blogs').empty();
    }
    else if (position = '-2808px') {
        $('#contact').load('pagefour.html #homepage');
        // hide the loading box 
        loadoff();
    }
    else {
        alert('all posibilities exausted');
    }
}
Run Code Online (Sandbox Code Playgroud)

Sha*_*oli 5

if条件是错误的.

更换===在这两个线

if ( position == '-1872px')

if ( position == '-2808px')
Run Code Online (Sandbox Code Playgroud)

如果是罚款,否则为FYI

if(postion = 'anything') //will always pass the if clause
Run Code Online (Sandbox Code Playgroud)