js jquery 扩展方法

时间:2023-08-02 15:02:20

//扩展Array,增加IsInAyyay函数。函数功能:判断数组是否包含某元素

Array.prototype.IsInAyyay=function(e) {

for (var i=0;i<this.length;i++)    {

if (this[i]==e)        {

return true;

}

}

return false;

}

/**
* 设置月下拉框
* 下拉框使用
* 默认当前月
*/
$.fn.ddlGetMonthFor = function () {
    var monthData = '[';
    var nowMonth = new Date().getMonth() + 1;
    for (var i = 1; i <= 12; i++) {
        var selected = "";
        if (monthData.length > 1) {
            monthData += ',';
        }
        if (i == nowMonth) {
            selected = "selected";
        }
        monthData += '{"Code":"' + i + '","Name":"' + i + '","selected":"' + selected + '"}';
    }
    monthData += ']';
    //查询开始月
    $(this).combobox({
        valueField: 'Code',
        textField: 'Name',
        width: 50,
        required: false,
        editable: false,
        multiple: false,
        panelHeight: 'auto',
        data: eval('(' + monthData + ')')
    });
}