Javascript语法错误:TypeError:'undefined'不是构造函数

时间:2013-07-15 17:03:17

标签: javascript

我在下面启动我的javascript时收到此错误:

if(isPartOfIndex(new Array[25,20], indexClaimTypeRow)    ){
        //display size

         listItem = '<li id="soze" data-theme="c"><h3>Size:</h3>' +
        '<div data-role="fieldcontain" data-theme="c">' +
          '<fieldset data-role="controlgroup" data-type="horizontal" id="recieptVat">' +
           '<input type="radio" name="radio-choice-1" id="radio-choice-1" value="1.0" />' +
            '<label for="radio-choice-1">1.0</label>' +
            '<input type="radio" name="radio-choice-1" id="radio-choice-2" value="1.4"  />' +
            '<label for="radio-choice-2">1.4</label>' +
            '<input type="radio" name="radio-choice-1" id="radio-choice-3" value="2.0"  />' +
            '<label for="radio-choice-3">2.0</label>' +
          '</fieldset>' +
        '</div>' +
      '</li>';

      $('#itemFieldslist').append(listItem);

      $('#itemFieldslist').listview('refresh');
    }

显示的错误信息是:

  

TypeError:'undefined'不是构造函数(评估'new   阵列[25,20]')

这里是isPartOfindex,它需要一个数组作为第一个参数

function isPartOfIndex(indexRow, indexType){

    for(var i = 0; i < indexRow.length; i++){
        if(indexRow[i] == indexType){
            return true;
        }
    }

    return false;

}

我做错了什么?

由于

3 个答案:

答案 0 :(得分:4)

应为new Array(25, 20)[25, 20]

答案 1 :(得分:1)

您需要将代码更改为:

   if(isPartOfIndex(new Array(25,20), indexClaimTypeRow)    ){
    //display size

     listItem = '<li id="soze" data-theme="c"><h3>Size:</h3>' +
    '<div data-role="fieldcontain" data-theme="c">' +
      '<fieldset data-role="controlgroup" data-type="horizontal" id="recieptVat">' +
       '<input type="radio" name="radio-choice-1" id="radio-choice-1" value="1.0" />' +
        '<label for="radio-choice-1">1.0</label>' +
        '<input type="radio" name="radio-choice-1" id="radio-choice-2" value="1.4"  />' +
        '<label for="radio-choice-2">1.4</label>' +
        '<input type="radio" name="radio-choice-1" id="radio-choice-3" value="2.0"  />' +
        '<label for="radio-choice-3">2.0</label>' +
      '</fieldset>' +
    '</div>' +
  '</li>';

  $('#itemFieldslist').append(listItem);

  $('#itemFieldslist').listview('refresh');
}

new Array [25,20]不是您阵列的正确声明。

答案 2 :(得分:1)

只需要[20, 25]而不是new Array[20, 25]。您也可以使用new Array(20, 25)