在IE中测试对象属性的存在

时间:2012-08-10 13:07:42

标签: javascript jquery internet-explorer

在IE中使用jQuery对我不起作用。

我有ajax回复:

{"update":{"WaterLever":null},"missing":["WaterBallast"]}

在回应时启动不同的功能:

$.post(...
...
function(data) {
  markMissing(data['missing']);
  fldUpdate(data['update']);
}

所有工作都在chrome / FF中,但在IE中只有fldUpdate。

IE找不到对象中的元素,尝试过.indexOf,(数据中的val)等...

function markMissing(data) {
  //loop all fields in form..
  $('[id^=cont]').each(function() {
    var s = this.id;
    //discard prefix 'cont_' in id. 
    var fld = s.substring(5);
    if(fld in data) { //this doesn't work
    //if(data.indexOf(fld)) { //this neither.
      $(this).addClass('missing');
    } else {
      $(this).removeClass('missing');
    }
  });
}

感谢任何输入

0 个答案:

没有答案
相关问题