未捕获的TypeError:无法读取属性'选项'未定义的

时间:2018-04-07 06:26:57

标签: javascript jquery uncaught-typeerror

我的代码为: -

function bindBranch(bankId) {
     $('#ddlbranch').unbind("change");
     $('#ddlbranch').get(0).options.length = 0
     $('#ddlbranch').get(0).options[0] = new Option("Select", "0");

     $.ajax({
         type: "POST",
         url: "InwardReportbranchwise.aspx/bindbranch",
         data: "{bankId:" + bankId + "}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (msg) {

             $.each(msg.d, function (index, item) {
                 $('#ddlbranch').get(0).options[$('#ddlbranch').get(0).options.length] = new Option(item.DisplayMember, item.ValueMember);
             });

             //if (type == "2")
             //    $(control).val(msg.d[0].branchesNationID).change();
             //else $(control).val(msg.d[0].BankId).change();

             $('#ddlbranch').bind("change", function () {
                 if ($(this).val() == "0") {
                     return;
                 }
                 bindControl($(this).val());
             });
             $('#ddlbranch').focus();

         },
         error: function () {
             alert('error');
         }
     })
 }

这是我的分行银行代码。我在第2行收到错误: -

  

无法阅读属性'选项'未定义的

0 个答案:

没有答案