顯示具有 jQuery 標籤的文章。 顯示所有文章
顯示具有 jQuery 標籤的文章。 顯示所有文章

2016年10月19日

金額 format string

var result = '0,0.' + Array(decimalPlace + 1).join('0')
result = result.replace(/\.\s*$/, "");
decimalPlace 0: "0,0"
decimalPlace 1: "0,0.0"
decimalPlace 2: "0,0.00"

參考:

Repeat Character N Times

2016年10月13日

懸浮按鈕 & 自動填入表單

懸浮按鈕
<input type="button" value="Import" style="positionL fixed; z-index: 10000; top: 95%; left: 5px;" onclick="$('#importFile').click()" />
<input id="importFile" type="file" style="position: fixed; z-index: 10000l top: -100px; left: -100px;" onchange="Import(this)" />
function Import(fileInput) {
    var reader;
    if(window.File && window.FileReader && window.FileList && window.Blob) {
        reader = new FileReader();
    }
    else {
        return;
    }

    var txtContent;
    if(fileInput.files && fileInput.files[0]) {
        reader.onload = function (e) {
            txtContent = e.target.result;
            console.log(txtContent);

            // Custom Code
            // End of Custom Code
        }
        reader.readAsText(fileInput.files[0]);

        //Reset
        fileInput.value = '';
    }
}

2014年3月3日

jqGrid Reload

jQuery("#list2").jqGrid('setGridParam',{data: json_History}).trigger("reloadGrid");

jQuery("#list2").jqGrid('setGridParam',{url:"server.php?q=2"}).trigger("reloadGrid");
reference
    jqGrid: Reload Local Data or Url Data

2013年10月8日

jqGrid 展開 subGrid by other columns

ondblClickRow: function (rowid, iRow, iCol, e) {
    alert("rowid: " + rowid + ", iRow: " + iRow + ", iCol: " + iCol);
    if (iCol == 2) {
        $(this).jqGrid("toggleSubGridRow", rowid);
    }
},
onCellSelect: function (rowid, iCol, cellcontent, e) {
    alert("rowid: " + rowid + ", iCol: " + iCol + ", cellcontent" + cellcontent);
    if (iCol == 2) {
        $(this).jqGrid("toggleSubGridRow", rowid);
    }
},

2013年8月13日

jQuery v.s. IE9 相同性

IE預設在 intranet的時候會使用 Document mode =IE 7的相容性
這樣會造成許多不可預期的 js錯誤

目前CSS使用的解法是在 master page head的部份加上以下 meta data使得他強迫使用ie10的文件模式(實測ie9也是ok)

    <meta http-equiv="Content-Type;" content="IE=10" />

如果本來就有資料的話可以用分號加上IE=10即可

jqGrid 換頁後, formatter失效

http://stackoverflow.com/questions/3807623/jqgrid-paging-question

$("#list").setGridParam({page:1}).trigger('reloadGrid');
$("#list").trigger("reloadGrid", [{page:1}]);
$("#list").trigger("reloadGrid", [{current:true}]);
使用無效?


用 bind綁定 click事件
$('td[id$=_pager]').click(function () {
    $('.buttonDownload').bind('click', Download);
});

function downloadButton(cellvalue, options, rowObject) {
    return "<input type='button' class='buttonDownload' value='列印' data-formTypeId='" +@Model.formTypeId +"' data-formNumber='" + cellvalue + "' />";
}

function Download() {
    var formTypeId = $(this).attr('data-formTypeId');
    var formNumber = $(this).attr('data-formNumber');
}
或 ...
function downloadButton(cellvalue, options, rowObject) {
    return "<input type='button' class='buttonDownload' onclick='javascript:Download(" + @Model.formTypeId + ", " + cellvalue + ");' value='列印' data-formTypeId='" +@Model.formTypeId +"' data-formNumber='" + cellvalue + "' />";
}

2012年12月3日

Popbox

<div id="divAddFolder" class="hideUC">
    <table>
        <tr>
            <td>
                資料夾名稱
            </td>
            <td>
                <input id="txtNewNodeName" type="text" />
            </td>
        </tr>
    </table>
    <input id="btnAddNode" type="button" value="確定" />
    <input id="btnCancelAddNode" type="button" value="取消" />
</div>

function PopupboxAdd() {
    $.blockUI({
        message: $('#divAddFolder'),
        css: {
            top: ($(window).height() - 300) / 2 + 'px',
            left: ($(window).width() - 300) / 2 + 'px',
            width: '300px'
        }
    });
}

jqueyr.blockUI.js
popbox.js

p.s. popupbox 會使 asp.net runat server onclick無法執行

2012年9月17日

Grid can not be used in this quirks mode

應該是 DOCTYPE非正規導致

ex:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

=>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">





jqGrid not rendered when the html page containing the grid is loaded through an ajax call

2012年9月14日

jqGrid on IE7 IE8

jqGrid 4.4.1 load data at once 在 IE8以下 高度會過長、pager會被蓋住看不到 solution: 用 3.7.2版本 & $('.ui-jqgrid-bdiv').css("height", "89%"); $("#jqgridRaw").jqGrid("setGridHeight", "90%");

2012年9月4日

jQuery 字串取代 replace

"Hello".replace(/ll/g,"qq");
var reg = new RegExp(billNumber + ',', 'g');
$("#number").html($("#number").html().replace(reg, ''));

replaceAll是用於取代元件

2012年8月31日

jQuery Table 欄位合併

jQuery : 分享合併Table的欄位 (RowSpan、ColSpan) 語法
////合併上下欄位(colIdx)
jQuery.fn.rowspan = function(colIdx) {
    return this.each(function() {
        var that;
        $('tr', this).each(function(row) {
            var thisRow = $('td:eq(' + colIdx + '),th:eq(' + colIdx + ')', this);
            if ((that != null) && ($(thisRow).html() == $(that).html())) {
                rowspan = $(that).attr("rowSpan");
                if (rowspan == undefined) {
                    $(that).attr("rowSpan", 1);
                    rowspan = $(that).attr("rowSpan");
                }
                rowspan = Number(rowspan) + 1;
                $(that).attr("rowSpan", rowspan);             
                $(thisRow).remove(); ////$(thisRow).hide();
            } else {
                that = thisRow;
            }
            that = (that == null) ? thisRow : that; 
        });
        alert('1');
    });
}

////當指定欄位(colDepend)值相同時,才合併欄位(colIdx)
jQuery.fn.rowspan = function(colIdx, colDepend) {
    return this.each(function() {
        var that;
        var depend;
        $('tr', this).each(function(row) {
            var thisRow = $('td:eq(' + colIdx + '),th:eq(' + colIdx + ')', this);
            var dependCol = $('td:eq(' + colDepend + '),th:eq(' + colDepend + ')', this);
            if ((that != null) && (depend != null) && ($(thisRow).html() == $(that).html()) && ($(depend).html() == $(dependCol).html())) {
                rowspan = $(that).attr("rowSpan");
                if (rowspan == undefined) {
                    $(that).attr("rowSpan", 1);
                    rowspan = $(that).attr("rowSpan");
                }
                rowspan = Number(rowspan) + 1;
                $(that).attr("rowSpan", rowspan);
                $(thisRow).remove(); ////$(thisRow).hide();
                
            } else {
                that = thisRow;
                depend = dependCol;
            }
            that = (that == null) ? thisRow : that;
            depend = (depend == null) ? dependCol : depend;
        });
    });
}

////合併左右欄位
jQuery.fn.colspan = function(rowIdx) {
    return this.each(function() {
        var that;
        $('tr', this).filter(":eq(" + rowIdx + ")").each(function(row) {
            $(this).find('th,td').each(function(col) {
                if ((that != null) && ($(this).html() == $(that).html())) {
                    colspan = $(that).attr("colSpan");
                    if (colspan == undefined) {
                        $(that).attr("colSpan", 1);
                        colspan = $(that).attr("colSpan");
                    }
                    colspan = Number(colspan) + 1;
                    $(that).attr("colSpan", colspan);
                    $(this).remove(); 
                } else {
                    that = this;
                }
                that = (that == null) ? this : that; 
            });
        });
    });
}


CODE-以jQuery實現Table相同欄位的上下合併
<script type="text/javascript">
        $(function () {
            //模擬顯示資料
            var data =
            [
                { No: "1", Name: "Jeffrey", Date: "2011/05/07", Score: 2011 },
                { No: "1", Name: "Jeffrey", Date: "2011/06/21", Score: 9999 },
                { No: "1", Name: "Jeffrey", Date: "2011/06/22", Score: 32767 },
                { No: "2", Name: "Mulder", Date: "2011/06/01", Score: 999 },
                { No: "3", Name: "Darkthread", Date: "2011/06/10", Score: 100 },
                { No: "3", Name: "Darkthread", Date: "2011/06/15", Score: 100 }
            ];
            var h = [];
            for (var i = 0; i < data.length; i++) {
                h.push("<tr>");
                var obj = data[i];
                for (var p in obj)
                    h.push("<td class='c-" + p + "'>" + obj[p] + "</td>");
                h.push("</tr>");
            }
            $("#scoreboard tbody").html(h.join('\n'));
 
            //合併內容相同欄位的邏輯
            $("#btnShowMe").click(function () {
                var $lastCell = null;
                var mergeCellSelector = ".c-No,.c-Name";
                $("#scoreboard tbody td.c-No").each(function () {
                    //跟上列的td.c-No比較,是否相同
                    if ($lastCell && $lastCell.text() == $(this).text()) {
                        //取得上一列,將要合併欄位的rowspan + 1
                        $lastCell.closest("tr").children(mergeCellSelector)
                        .each(function () {
                            this.rowSpan = (this.rowSpan || 1) + 1;
                        });
                        //將本列被合併的欄位移除
                        $(this).closest("tr").children(mergeCellSelector).remove();
                    }
                    else //若未發生合併,以目前的欄位作為上一欄位
                        $lastCell = $(this);
                });
            });
        });
    </script>

<table id="scoreboard">
    <thead>
        <tr><td>No</td><td>Name</td><td>Date</td><td>Score</td></tr>
    </thead>
    <tbody>
    </tbody>
</table>
void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Cells[0].CssClass="SubProjectTd";
        // 在每一個 row的第一個 column加上 class
    }
}

2012年8月30日

jQuery Multi Select 動態預設多選

如果選項是用 javascript在前台塞進去的
想要預選就得先將 select元件設定 multiple

$("#ddlSurvey").attr("multiple", "multiple");
$("#ddlSurvey").multiselect({...});
$("#ddlSurvey").multiselect('refresh');

2012年8月28日

Highchart 沒有顯示圖

有框 沒圖

1. 設定變數時,數字給成字串

    ex: var hy_legend_y  = "50";

    IE還是可以顯示;Chrome、Firefox就不能

2. Highcharts line chart does not work with jQuery 1.7.

     highchart not shown data graph

2012年8月21日

jQuery Readonly v.s. Disable

input元件若設定為 disable submit時就會以空值的方式送到後台, 應用 readonly

2012年8月17日

jQuery div內字串比對總是回傳 false

ex:
result = ($(this).html()=="SubProject");
result: false


加上 .trim()即可
result = ($(this).html().trim()=="SubProject");
result: true

2012年7月18日

jQuery .keyup() 即時偵測輸入字串

$(function () {
    $("#aspQueryString").keyup(function () {
        if ($(this).attr("value").length > 100) { 
        }
    });
});