2021年8月22日 星期日

使用jQuery將資料快速填充到表單

jQuery form autofill 


function loadData(jsonStr) {

    var obj = eval("(" + jsonStr + ")");

    var key, value, tagName, type, arr;

    for (x in obj) {

        key = x;

        value = obj[x];

        $("[name='" + key + "'],[name='" + key + "[]']").each(function() {

            tagName = $(this)[0].tagName;

            type = $(this).attr('type');

            if (tagName == 'INPUT') {

                if (type == 'radio') {

                    $(this).attr('checked', $(this).val() == value);

                } else if (type == 'checkbox') {

                    arr = value.split(',');

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

                        if ($(this).val() == arr[i]) {

                            $(this).attr('checked', true);

                            break;

                        }

                    }

                } else {

                    $(this).val(value);

                }

            } else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {

                $(this).val(value);

            }

        });

    }

}

【2026 最新】VS Code 導入 pstack AI Skills 完整教學:用 Copilot 打造嚴謹的 Agent 工作流

在 VS Code 使用 AI Skills 打造嚴謹工程工作流:從 pstack 到原生 AGENTS.md 實戰指南 「If you want to go fast, go deep first.」 — Lauren Tan(@poteto) 進入 2026 年, AI Co...