Material Design Lite-JS未应用事件监听器

时间:2018-08-04 00:27:17

标签: javascript html material-design-lite

我在Material Design Lite库中遇到了一个奇怪的问题。根据文档,在关闭body标记之前,我已经包含了mdl js脚本标记。 但是,我无法从mdl库应用样式。在检查开发工具后,我发现material.min.js的事件侦听器未应用于文本字段和按钮等。我附加了两个图像以更好地解释这种情况。

MDL files are being loaded correctly.

如您所见,文件正在加载...

Styling not working as intended

但是我看不到MDL中文本字段的任何动画。

PS。我正在本地服务器上运行网站。 任何帮助将不胜感激。谢谢...

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <title>Page Title</title>
    <!-- google font -->
    <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet" type="text/css" />
    <!-- icons -->
    <link href="/static/portal/assets/fonts/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
    <link href="/static/portal/assets/fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <!--bootstrap -->
    <link href="/static/portal/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

    <!-- Material Design Lite CSS -->
    <link rel="stylesheet" href="/static/portal/assets/plugins/material/material.min.css">
    <link rel="stylesheet" href="/static/portal/assets/css/material_style.css">
    <!-- Theme Styles -->
    <link href="/static/portal/assets/css/theme/light/theme_style.css" rel="stylesheet" id="rt_style_components" type="text/css" />
    <link href="/static/portal/assets/css/theme/light/style.css" rel="stylesheet" type="text/css" />
    <link href="/static/portal/assets/css/plugins.min.css" rel="stylesheet" type="text/css" />
    <link href="/static/portal/assets/css/responsive.css" rel="stylesheet" type="text/css" />
    <link href="/static/portal/assets/css/theme/light/theme-color.css" rel="stylesheet" type="text/css" />
</head>
<body class="page-header-fixed sidemenu-closed-hidelogo page-content-white page-md">
...
<!-- start js include path -->
<script src="/static/portal/assets/plugins/jquery/jquery.min.js" ></script>
<script src="/static/portal/assets/plugins/popper/popper.js" ></script>
<script src="/static/portal/assets/plugins/jquery-blockui/jquery.blockui.min.js" ></script>
<script src="/static/portal/assets/plugins/jquery-slimscroll/jquery.slimscroll.js"></script>
<!-- bootstrap -->
<script src="/static/portal/assets/plugins/bootstrap/js/bootstrap.min.js" ></script>
<!-- Common js-->
<script src="/static/portal/assets/js/app.js" ></script>
<script src="/static/portal/assets/js/layout.js" ></script>
<script src="/static/portal/assets/js/theme-color.js" ></script>
<!-- Material -->
<script src="/static/portal/assets/plugins/material/material.min.js"></script>
<script src="/static/portal/assets/js/pages/material-select/getmdl-select.js" ></script>
<script  src="/static/portal/assets/plugins/material-datetimepicker/moment-with-locales.min.js"></script>
<script  src="/static/portal/assets/plugins/material-datetimepicker/bootstrap-material-datetimepicker.js"></script>
<script  src="/static/portal/assets/plugins/material-datetimepicker/datetimepicker.js"></script>
<!-- dropzone -->
<script src="/static/portal/assets/plugins/dropzone/dropzone.js" ></script>
<script src="/static/portal/assets/plugins/dropzone/dropzone-call.js" ></script>
<!-- end js include path -->


</body>
</html>

2 个答案:

答案 0 :(得分:1)

这是MDL按钮的一个非常基本的工作示例,可以作为故障排除中的参考。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Material Design Lite Button example</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
</head>

<body>

  <!-- Accent-colored raised button with ripple -->
  <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
    Button
  </button>

  <script src="https://code.getmdl.io/1.3.0/material.min.js"></script>

</body>

</html>

答案 1 :(得分:0)

我的问题是我正在从模板中复制粘贴渲染的小部件,该小部件已经添加了data-upgraded属性。只需遵循MDL文档,就可以了。