2014年1月28日 星期二

檔案大小format

function formatDataSize(kb) {
    if (kb == '')
        return "";
    kb = parseInt(kb);
    var mb = kb / 1024;
    if (mb >= 1)
        return formatFloat(mb, 2) + " MB";
    else
        return kb + " KB";
}

function formatFloat(num, pos) {
    var size = Math.pow(10, pos);
    return Math.round(num * size) / size;
}

時間format

function formatTime(sec) {
    if (sec == '')
        return "";
    sec = parseInt(sec);
    var hour = parseInt(sec / 3600);
    var min = parseInt(sec / 60);
    sec = sec % 60;
    return hour + ":" + (min < 10 ? '0' + min : min) + ":" + (sec < 10 ? '0' + sec : sec);
}

2014年1月26日 星期日

找不到圖片 使用預設圖片

            //使用預設封面
            $('#AlbumList table img').error(function () {
                $(this).attr("src", "./images/album.jpg");
            });

2014年1月23日 星期四

textbox 指標到最後

$("#keyword").focus().val('').val(keyword);

鍵盤 Key Enter 事件

    $("#keyword").keypress(function (e) {
       //enter事件
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $("#search").click();
            return false;
        } else {
            return true;
        }
    });

checkBox 設定全選

    //設定全選
    $("#selectAll").click(function () {
        var isCheck = $(this).prop("checked");
        $("input[name='photoItem']").prop("checked", isCheck);
    });

checkbox 多檔案 刪除

    //刪除檔案
    $("input[name='delete']").click(function () {
        var IDArray = [];
        $("input[name='file']:checked").each(function () {
            IDArray .push($(this).val());
        });

        if (IDArray .length == 0) {
            alert("請至少勾選一個檔案!");
            return false;
        }
        deleteFile(IDArray );
    });

checkBox只能單選

    //設定checkBox 只能單選
    $("#AlbumList table").delegate("input[name='albumItem']", "click", function () {
        var isCheck = $(this).prop("checked");
        if (isCheck) {
            $("#AlbumList table input[name='albumItem']").prop("checked", false);
            $(this).prop("checked", true);
        }
    });