动态添加checkboxradio

时间:2014-06-28 18:59:26

标签: jquery-mobile

我有一个包含2个checkboxradios的html页面。有一个按钮,应该删除所有单选按钮并通过ajax加载新的按钮。

我已经完成了所有工作,但是css存在一个小问题。这是打开页面时我的单选按钮的样子: enter image description here

在我删除无线电并通过AJAX加载新无线电之后,这就是它的样子: enter image description here

我的HTML看起来像这样:

<div data-role="fieldcontain">
    <fieldset data-role="controlgroup" id="campaignselection">
    <input type="radio" name="campaign" id="autosalon_genf_2015" value="autosalon_genf_2015" checked="checked">
    <label for="autosalon_genf_2015">Autosalon Genf</label>
    <input type="radio" name="campaign" id="auto_zuerich_2014" value="auto_zuerich_2014">
    <label for="auto_zuerich_2014">Auto Zürich</label>
</fieldset>

这是执行更新的jQuery部分:

$("#updatevalues").click(function() {
// Download campaign codes
$.ajax({
    type: "GET",
    dataType: "json",
    url: 'http://hostname.com/api/directory',
    success: function(response) {
        // Remove all campaign entries from the current list
        $("#campaignselection").empty();
        $.each(response, function() {
            $("#campaignselection").append('<input type="radio" name="campaign" id="' + this.code + '" value="' + this.code + '" />');
            $("#campaignselection").append('<label for="' + this.code + '">' + this.label_de + '</label>');
            $("#" + this.code).checkboxradio();
            $("#" + this.code).checkboxradio("refresh");
        });

        //$("#campaignselection").trigger("create");
        //$("input[type='radio']").checkboxradio();
        //$("input[type='radio']").checkboxradio("refresh");
    }
});
})

我还有其他方法要执行吗? jQuery mobile的版本是1.4.2。

0 个答案:

没有答案
相关问题