javascript - MDL 动画停止处理复制的 <fieldset>

标签 javascript jquery material-design-lite

我在克隆表单的一部分(使用 jQuery)时遇到问题。

下面的代码复制“字段集”,应用唯一的 ID 和 for,然后将副本附加到原始“字段集”中。

尽管复制有效,但“MDL”框架的所有动画都会在复制的“fieldset”上中断。

我使用的代码如下所示:

//When add section is pressed
$('#add-section').click(function () {
    // add 2 vars to count clicks per page

    // get the fieldset's children that user is on, and clone it
    var $fieldsetCopy = $('form>:nth-child(' + pageNumber + ')').clone();

    // add '-2' to all id's of the cloned fieldset
    $fieldsetCopy.find("*[id]").each(function () {
        $(this).attr("id", $(this).attr("id") + "-2");
    });

    // add '-2' to all for's of the cloned fieldset
    $fieldsetCopy.find("*[for]").each(function () {
        $(this).attr("for", $(this).attr("for") + "-2");
    });

    // remove the first p element of the clone
    $fieldsetCopy.find("p").first().remove();

    // add the cloned fieldset within the original
    $fieldsetCopy.appendTo('form>:nth-child(' + pageNumber + ')');
    $()
});

我猜测 JavaScript 加载有问题?

最佳答案

我最终自己找到了答案。问题是框​​架需要重新加载。为此,您可以使用以下行:

componentHandler.upgradeAllRegistered();

或者,如果您想定位特定元素,可以使用:

componentHandler.upgradeElement(button);
<小时/>

完整的文档在这里 https://getmdl.io/started/#dynamic

关于javascript - MDL 动画停止处理复制的 <fieldset>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35855543/

相关文章:

javascript - 谷歌图像使用什么 javascript 框架进行缩放?

javascript - ng-animate 无法在 angularjs 1.1.5 中与 ng-show 一起使用

jquery - 如何循环播放 jquery.cycle() 幻灯片两次

javascript - ng-if 消除了 Material Design lite 涟漪效应

javascript - 使用 audio.srcObject 和 MediaStream 播放来自 ajax 调用的音频

javascript - 缓存文档对象对性能有什么好处吗?

javascript - TypeError : jQuery(. ..).ready(...) 不是一个函数

jQuery CSS3 转换无法旋转 DiV

css - 使用 Material Design 卡片 div 元素,但卡片中的内容不会居中

jquery - 如果稍后添加元素,mdl-js-textfield 将不起作用