Firefox中没有更新AJAX选择框

时间:2013-09-08 11:05:17

标签: jquery ajax firefox select option

我有一个由ajax填充的选择框。但是我需要使用ajax更改选择选项。以下代码在IE中工作但不是Firefox。请帮忙。

var tts = $("select#myList option");   //collected all options
   tts.each(function(i){
        var cpid = this.attributes['pankti'].value; // check for desired rel tag
        if(cpid === ppid) { 
          this.attr('selected','selected');   //...and select this option
        }else{
          this.removeAttr('selected','');     //.. else clear selection
        }
      });

2 个答案:

答案 0 :(得分:1)

试试这个

var tts = $("select#myList option");   //collected all options
   tts.each(function(i){
        var option= $(this);
        var cpid = option.attr('pankti'); // check for desired rel tag
        if(cpid === ppid) { 
          option.attr('selected','selected');   //...and select this option
        }else{
          option.removeAttr('selected','');     //.. else clear selection
        }
      });

答案 1 :(得分:0)

您还可以尝试更改以下行:

option.attr('selected','selected');

option.prop('selected','selected');