从javascript函数存储变量

时间:2013-07-27 18:31:05

标签: javascript

我正在尝试在运行函数后将字符串存储到变量中。当它运行时,它返回undefined。在底部我尝试添加return marginDirection;但它仍然返回未定义。我不确定我哪里出错了。我已经陷入困境。任何帮助,将不胜感激!感谢

var marginDirection = getMarginDirection();

            function getMarginDirection() {
                if (floatDirection == 'right') { 
                    marginDirection == 'left'; 
                    } 
                else if (floatDirection == 'left') { 
                    marginDirection == 'right'; 
                    } 
                else { 
                    marginDirection == ''; 
                    }
                };

1 个答案:

答案 0 :(得分:2)

function getMarginDirection()
{
    if (floatDirection == 'right')
        marginDirection = 'left'; 
    else if (floatDirection == 'left')
        marginDirection = 'right'; 
    else
        marginDirection = '';

    return marginDirection;
}

Return变量并指定=而不是==

的值