js判断对象属性,并追加

来源:互联网 发布:freebsd mysql 编辑:程序博客网 时间:2024/06/05 07:37
/**     * 消息提示(轻)     * @method msgTip     * @param {String} msg 必选 提示内容     * @param {time: 持续时间, top: top, left: left, bottom: bottom, right: right} 可选     */    Base.msgTip = function(msg, param) {    if(arguments.length == 1) {    param = {};    }    var _t = param["time"] || 2000;    var style = "style='";    var _top = param["top"];    if(_top) {    style += "top:"+_top+";";    }    var _bottom = param["bottom"];    if(_bottom) {    style += "bottom:"+_bottom+";";    }    var _left = param["left"];    if(_left) {    style += "left:"+_left+";";    }    var _right = param["right"];    if(_right) {    style += "right:"+_right+";";    }    style += "'";    var $div = $("<div class=\"md-msgtip\" "+style+"><div class='mm-msg'>" + msg + "</div></div>");    $("body").append($div);    setTimeout(function() {    $div.remove();    }, _t);    }    /** * 存入本地存储 *  * @method setStorage * @param {String} k 必选 键 * @param {Object} val 必选 值 */



param是一个对象,param["top"]、param["bottom"]、param["left"]、param["right"]只是判断其对象中的属性,存在就赋值给var _top,不存在值就为undefined

0 0
原创粉丝点击