0

I'm creating a select Options dynamically under a using jquery. I have set the first item as selected using selected attribute. But i couldn't able to see the first item in select list. if i select second or third item the text is displaying in select tag.enter image description hereenter image description hereenter image description here

EDIT : and one more thing i need to say,here am using jquery mobile framework.

Can any one help me.

here is my HTML script :

<select id="HRselectList"></select>

JS :

for(var x = 0; x <= 5; x++)
{
  $('#HRselectList').append($("<option></option>").attr("value",x).text(x));
  if(x==0)
  {
    $('#HRselectList option').attr("selected","selected");
  }
}
4

2 回答 2

0

我测试了您的代码,但没有发现问题。但是,我确实认为我知道问题出在哪里。试试这个...

var HRselectList = $('#HRselectList'),
    x = 0;

for (; x < 6; x++) {
    HRselectList.append($("<option></option>").attr("value", x).text(x));
}

HRselectList.find('option').eq(0).attr("selected", "selected");​

...让我知道它是否有效。

这是一个小提琴:http: //jsfiddle.net/joplomacedo/ggmHe/

于 2012-08-02T13:41:45.583 回答
-1

检查这个http://jsfiddle.net/GTyZ3/1/

如果您正在使用 jquery mobile,我认为更简单的方法可能会一直走下去。这是一个有点不成熟的方法,但我希望它会奏效。

于 2012-08-02T13:46:30.777 回答