繁体   English   中英

Material Design Lite 开关不适用于 jquery 负载

[英]Material Design Lite Switch not working on jquery load

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

这是我的主页代码: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 无法正常工作,但我找不到解决此问题的方法。 请帮忙

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

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

暂无
暂无

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

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