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