最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Split causes "Object doesn't support this property or method" exception - Stack Overflow

programmeradmin2浏览0评论

call to split on a variable causes a "Object doesn't support this property or method" exception and I don't know why. Here's my code:

function getKontaktPersonen(kontaktSelectBox) {
   var kontaktPersonen = [];
   var id_and_name = kontaktSelectBox.attr('id');
   var id_part = getID_PartFromName(id_and_name);
   var textboxname;
   var selectboxname;
   if (kontaktSelectBox.attr('class') == 'kontaktSelectBox') {

        textboxname = "TextBoxKunde" + id_part;
        selectboxname = "SelectBoxKontaktPerson" + id_part;
    } else if (kontaktSelectBox.attr('class') == 'NewkontaktSelectBox') {
        textboxname = "NewTextBoxKunde" + id_part;
        selectboxname = "NewSelectBoxKontaktPerson" + id_part;
    } else {
        return false;
    }
    var kundeBox = $('#' + textboxname);
    var kundeBoxVal = kundeBox.val();
    if (kundeBoxVal != '' && kundeBoxVal != null) {
     var adr_id = kundeBoxVal.split(';')[1];
      //here es an ajax call
      //[...]
    }
}

call to split on a variable causes a "Object doesn't support this property or method" exception and I don't know why. Here's my code:

function getKontaktPersonen(kontaktSelectBox) {
   var kontaktPersonen = [];
   var id_and_name = kontaktSelectBox.attr('id');
   var id_part = getID_PartFromName(id_and_name);
   var textboxname;
   var selectboxname;
   if (kontaktSelectBox.attr('class') == 'kontaktSelectBox') {

        textboxname = "TextBoxKunde" + id_part;
        selectboxname = "SelectBoxKontaktPerson" + id_part;
    } else if (kontaktSelectBox.attr('class') == 'NewkontaktSelectBox') {
        textboxname = "NewTextBoxKunde" + id_part;
        selectboxname = "NewSelectBoxKontaktPerson" + id_part;
    } else {
        return false;
    }
    var kundeBox = $('#' + textboxname);
    var kundeBoxVal = kundeBox.val();
    if (kundeBoxVal != '' && kundeBoxVal != null) {
     var adr_id = kundeBoxVal.split(';')[1];
      //here es an ajax call
      //[...]
    }
}
Share Improve this question edited Feb 9, 2012 at 9:16 gdoron 150k59 gold badges302 silver badges371 bronze badges asked Feb 9, 2012 at 8:15 LukeLuke 5,98113 gold badges58 silver badges77 bronze badges 2
  • make sure that it is not null – Diode Commented Feb 9, 2012 at 8:21
  • @Luke. What version? Try the code in Chrome or FF. – gdoron Commented Feb 9, 2012 at 9:16
Add a ment  | 

1 Answer 1

Reset to default 2

If the selector didn't find any element the val function will return undefined Try this:

if (kundeBoxVal) {
     var adr_id = kundeBoxVal.split(';')[1];
 }
发布评论

评论列表(0)

  1. 暂无评论