JQuery常用写法

2017-04-10 21:33:31 .net
$(function() {
        //主物资分包编号初始化
        var selectpackages = $("select[name='spackageindex']");
        var hipackages = $("input[name='hipackageindex']");
        var packagecount = $('#<%=txtCount.ClientID %>').attr("value");
        for (var i = 0; i < selectpackages.length; i++) {
            //selectpackages.item(i).options.length = 0;
            for (var m = 1; m <= packagecount; m++) {
                selectpackages[i].options.add(new Option(m, m));
            }
            selectpackages[i].value = hipackages[i].value;
        }
        //子物资分包编号初始化
        var selectpackagesson = $("select.hai");
        var hipackagesson = $("input[name='hipackageindexson']");
        for (var k = 0; k < hipackagesson.length; k++) {
            if (hipackagesson[k].value != "") {
                for (var m = 1; m <= packagecount; m++) {
                    selectpackagesson[k].options.add(new Option(m, m));
                }
                selectpackagesson[k].value = hipackagesson[k].value;
            }
        }
    });