我试图通过外部文件加载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>以下是我按load按钮后的结果:

可能的js不能正常工作,但是我找不到解决这个问题的方法。请帮帮忙
发布于 2016-04-09 22:08:52
您需要调用componentHandler.upgradeAllRegistered()来获取动态的dom。
发布于 2020-11-11 19:45:18
在视图的最底部添加componentHandler.upgradeAllRegistered() (本例中为new_test.php)。
https://stackoverflow.com/questions/36475782
复制相似问题