0

我有一个由 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
        }
      });
4

2 回答 2

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
        }
      });
于 2013-09-08T11:08:07.853 回答
0

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

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

option.prop('selected','selected');
于 2014-01-17T17:19:08.860 回答