简体   繁体   English

初始化在物化中动态添加的单选按钮

[英]initializing radio buttons added dynamically in materialize

I have an ajax request that generates a modal window with radio buttons dynamically. 我有一个ajax请求,动态生成带有单选按钮的模态窗口。

I see in the materialize documentation that you can execute material_select() to get selects working correctly however, I don't see in the documentation how to initialize a radio dynamically. 我在实体文档中看到你可以执行material_select()以使selects正常工作,但是我没有在文档中看到如何动态初始化一个radio

How do i initialize dynamically loaded radio buttons? 如何初始化动态加载的单选按钮?

For reference here is in example modal that I am loading dynamically: 这里参考的是我动态加载的示例模态:

<div id="import-modal" class="modal modal-fixed-footer">
    <div class="modal-content">
        <h4>Import Data</h4>
        <p>
            <input name="import-group" type="radio" id="import-modal-csv"/>
            <label for="import-modal-csv">Csv</label>
            <div>Import a csv file.</div>
        <p/>
        <p>
            <input name="import-group" type="radio" id="import-modal-excel"/>
            <label for="import-modal-excel">Excel</label>
            <div>Import a excel file.</div>
        </p>
    </div>
    <div class="modal-footer">
        <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Import</a>
    </div>
</div>

edit 1 编辑1

i'm adding the above div dynamically via jquery to a parent container on click of a button: 我通过jquery动态地将上面的div添加到父容器中click按钮:

        import_click: function(){
            $.ajax({
                url: 'template/import.html',
                success: function (response) {
                    $('#container').append(response);
                }
            });
        }

The radio buttons do not require any javascript initialization. 单选按钮不需要任何javascript初始化。 Just make sure when you append them dynamically to give them new ID's because if they conflict with existing radio buttons, they will not work. 只需确保动态附加它们以给它们新的ID,因为如果它们与现有的单选按钮冲突,它们将无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM