【问题标题】:Material Design Lite Switch not working on jquery loadMaterial Design Lite Switch 不适用于 jquery 负载
【发布时间】:2016-07-28 07:28:16
【问题描述】:

我正在尝试通过外部文件加载 MDL 开关,但它不起作用。

这是我的主页代码:index.php

<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="material.min.css">
</head>

<body>
<a href="#" class="lo">Load</a>
<div class="demo-switch">

<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-2">
<input type="checkbox" id="switch-2" class="mdl-switch__input" />
<span class="mdl-switch__label">Bluetooth</span>
</label>

</div>

<script src="js/material.min.js"></script>
<script src="js/jquery.js"></script>
<script>
$(document).ready(function(){

  $.getScript("js/material.min.js").done(function(){

      $(document).on("click",".lo",function(){
      $('.demo-switch').load("new_test.php");
      });
  });



});

</script>

</body>
</html>

这里是文件 new_test.php

<div class="demo-switch">

<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-2">
<input type="checkbox" id="switch-2" class="mdl-switch__input" />
<span class="mdl-switch__label">Bluetooth</span>
</label>

</div>

这是我按下加载按钮后的结果:

可能的 js 无法正常工作,但我找不到解决此问题的方法。 请帮忙

【问题讨论】:

    标签: javascript php jquery html material-design


    【解决方案1】:

    您需要为动态 dom 调用 componentHandler.upgradeAllRegistered()

    【讨论】:

      【解决方案2】:

      在视图的最底部添加componentHandler.upgradeAllRegistered()(在本例中为new_test.php)。

      【讨论】:

        猜你喜欢
        • 2021-04-25
        • 1970-01-01
        • 2016-06-23
        • 1970-01-01
        • 2016-05-22
        • 2016-07-02
        • 1970-01-01
        • 1970-01-01
        • 2015-11-09
        相关资源
        最近更新 更多