我正在尝试在运行函数后将字符串存储到变量中。当它运行时,它返回undefined。在底部我尝试添加return marginDirection;
但它仍然返回未定义。我不确定我哪里出错了。我已经陷入困境。任何帮助,将不胜感激!感谢
var marginDirection = getMarginDirection();
function getMarginDirection() {
if (floatDirection == 'right') {
marginDirection == 'left';
}
else if (floatDirection == 'left') {
marginDirection == 'right';
}
else {
marginDirection == '';
}
};
答案 0 :(得分:2)
function getMarginDirection()
{
if (floatDirection == 'right')
marginDirection = 'left';
else if (floatDirection == 'left')
marginDirection = 'right';
else
marginDirection = '';
return marginDirection;
}
Return
变量并指定=
而不是==