2013-03-14 52 views
0

每次用戶訪問選項卡菜單時,都會嘗試刷新單選按鈕的列表。第一次訪問樣式是可以的,但它們表現得像複選框,並且當其他單選按鈕被點擊時不能被取消選中。單選按鈕不會動態應用樣式

我試圖把refresh();方法,但它仍然無法正常工作。

你可以看到JSFIDDLE

任何建議的演示?謝謝。

$('.export_tab').click(function(){ 
    $("#radios_wrapper").children().remove(); //Remove all previous radio buttons 
    for(var i in localStorage) //Looping through the localStorage 
     { 
      dataIndex = JSON.parse(localStorage[i]).index; 
      dataName = JSON.parse(localStorage[i]).name; 
        //Then insert a new one 
      $("#radios_wrapper").append('<input type="radio" value="'+dataIndex+'" name="'+dataIndex+'" id="radio'+dataIndex+'"/><label for="radio'+dataIndex+'">'+dataName+'</label>'); 
     } 
}); 

這是HTML

<div data-role="fieldcontain"> 
    <fieldset data-role="controlgroup" id='radios_wrapper'> 

    </fieldset> 
</div> 
+0

提供演示:[JS Bin](http://jsbin.com/),[jsFiddle](http://jsfiddle.net/)等。 – 2013-03-14 05:04:32

+0

http://jsfiddle.net/w4gQa/1/幹得好。 – 2013-03-14 05:22:51

回答

0

單選按鈕需要相同的名稱,成爲一組。所以:

'<input type="radio" value="'+dataIndex+'" name="'+dataIndex+'"/>' 

不是正確的方法。這個名字對於你想分組的所有收音機應該是一樣的。它應該是:

'<input type="radio" value="'+dataIndex+'" name="allTheSame"/>' 

這裏是更新了自己的Fiddle

要告訴jQuery重繪使用觸發器功能,如.append('whatever').trigger('create')http://jquerymobiledictionary.pl/faq.html。更新Fiddle

+0

我試過了。它仍然不起作用。在這裏看到演示。 http://jsfiddle.net/w4gQa/1/ – 2013-03-14 05:23:21

+0

@PakinaiKamolpus:你的小提琴並不是我說的。查看我的更新。 – 2013-03-14 05:27:58

+0

好的。但他們仍然不適用這種風格。 – 2013-03-14 05:29:17