当前位置 : 主页 > 网页制作 > JQuery >

正式参数后jquery / javascript缺失)

来源:互联网 收集:自由互联 发布时间:2021-06-15
嗨,我有这个代码: function getFullnameDetails(mainHeight,upperstyle,type=''){ setTimeout(function(){fullnameCenter(mainHeight,upperstyle,type='')},2000);}function fullnameCenter(mainHeight,upperstyle,type=''){ var distOfMainAndUpper
嗨,我有这个代码:

function getFullnameDetails(mainHeight,upperstyle,type=''){
    setTimeout(function(){fullnameCenter(mainHeight,upperstyle,type='')},2000);
}
function fullnameCenter(mainHeight,upperstyle,type=''){
    var distOfMainAndUpper = mainHeight - upperstyle;
    var mainHalfHeight = mainHeight/2;
    var imageHeight = jQuery("img[rel='fullname']").height(); //there is a delay
    var imageHalfHeight = imageHeight/2;
    var fromImageTopToMainHalf = mainHalfHeight - imageHeight;
    var position = imageHalfHeight+fromImageTopToMainHalf-distOfMainAndUpper;
    if(type == 'big'){ jQuery("#temp .test1").css("bottom",position+"px"); }
    else { jQuery(".test1").css("bottom",position+"px"); }


}

在形式参数之后它说我失踪了.
这发生在这一行:

function getFullnameDetails(mainHeight,upperstyle,type=''){ //IT HAPPENS HERE! :)
    setTimeout(function(){fullnameCenter(mainHeight,upperstyle,type='')},2000);
}

我在这做错了什么.

在此先感谢您的帮助 :)

Javascript不支持默认函数参数值.

你可以做这样的事情(但要警惕意外的’假的’价值观):

function getFullnameDetails(mainHeight,upperstyle,type){
  type = type || ''; // if type is 'falsey' (null, undefined, empty string) assign ''
  //...
}
网友评论