2013-03-14 54 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