【问题标题】:Radio Buttons are not applying style dynamically单选按钮没有动态应用样式
【发布时间】:2013-03-02 08:18:58
【问题描述】:

每次用户访问标签菜单时,我都会尝试刷新单选按钮列表。首次访问样式还可以,但它们的行为类似于复选框,并且在单击其他单选按钮时无法取消选中。

我尝试过使用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>

【问题讨论】:

标签: css jquery-mobile radio-button


【解决方案1】:

单选按钮需要相同的名称才能成为一个组。所以:

'<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。

【讨论】:

  • 我试过了。它仍然无法正常工作。在此处查看演示。 jsfiddle.net/w4gQa/1
  • @PakinaiKamolpus:你的小提琴不像我说的那样。查看我的更新。
  • 好的。但他们仍然没有应用样式。
  • 风格?我在您的帖子或小提琴中看不到任何样式代码。
  • 我明白了。我更新了我的答案和你的小提琴。也许这有帮助。
猜你喜欢
  • 2016-12-05
  • 1970-01-01
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
  • 1970-01-01
  • 2015-04-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多