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 に答える