php - MDL- componentHandler.upgradeDom();在ajax调用之后

我使用 Google Material Design Lite 进行了以下 ajax 设置:

first.php

<button class="rhm_add_button" type="button" >
    Show                      
</button>
<div class="rhm_add"></div>


<script>
jQuery(document).ready(function() {
            jQuery('.rhm_add_button').click(function(e) {
                e.preventDefault();
                jQuery.ajax({
                    type: "GET",
                    url: "<?php echo admin_url('admin-ajax.php'); ?>", 
                    dataType: 'html',
                    data: ({ action: 'rhmp_indi_form'}),
                    success: function(data){
                            jQuery('.rhm_add').html(data);
                },                  
                error: function(data)  
                {  
                alert("Error!");
                return false;
                }  
                }); 
         }); 
     }); 
</script>

Functions.php

function rhmp_indi_form_callback() {  
    $template_part_path = 'page-parts/second_page';
    get_template_part($template_part_path);
    exit;
}
add_action('wp_ajax_rhmp_indi_form', 'rhmp_indi_form_callback');
add_action('wp_ajax_nopriv_rhmp_indi_form', 'rhmp_indi_form_callback');

Second_file.php

 <div class="mdl-textfield mdl-js-textfield">                                       
    <input class="mdl-textfield__input" type="text" id="title" name="title"/>
    <label class="mdl-textfield__label" for="title">Name</label>                                        
 </div>

如您所见,我正在使用 MDL,当通过 ajax 加载内容时,它们无法正常工作,我从 github 中找到了以下解决方案:https://github.com/google/material-design-lite/issues/1043

解决方案是我需要使用“componentHandler.upgradeDom();”在 ajax 调用之后,我不确定该怎么做。

有人知道如何实现吗?

谢谢!

最佳答案

在将任何动态元素插入 DOM 后调用 componentHandler.upgradeDom()

在你的例子中,在 jQuery('.rhm_add').html(data) 之后调用它

https://stackoverflow.com/questions/33061979/

相关文章:

ruby-on-rails - 如何显示 Time.now 基于 TimeZone - Rails

c# - 如何从整数生成 MD5 哈希(32/64 个字符)

java - 在时区字符串列表中根据 GMT 时间对时区进行排序

drupal - 在新的 Drupal 8 站点上,子菜单链接没有出现?

c# - 如何等待 UploadStringAsync 方法完成

vim - 如何在 Vim 中快速上下(ctrl u 和 ctrl d)重新映射到 ctrl j 和

linux-kernel - BUILDROOT ip : can't find device et

google-apps-script - 谷歌应用程序脚本编辑器中的自动完成并不总是知道类型/上下文

bash - 将 Bash Shell 变量传递给 Awk NR 函数

jquery - VideoJS - 播放视频时,暂停所有其他视频