材料设计精简附加图标

时间:2017-07-15 09:47:02

标签: javascript css material-design

我遇到附加使用材质图标的问题似乎没有加载css / js而是显示单词check

- 这部分来自stepper.js

var i = document.createElement('i');
                        i.style.className = 'material-icons';
                        var text = document.createTextNode('check');
                        i.appendChild(text);


                        elements.appendChild(i);

我想知道我将如何重新加载js文件或重新加载材料字体部分?'

我的标题 - 我如何加载styesheet和js

 <script type="text/javascript">
 var uid = '{$smarty.session.ipet_user}';
 {literal} 

    function stylesheet(url) {
            var s = document.createElement('link');
            s.rel = 'stylesheet';
            s.async = false;
            s.href = url;
            var x = document.getElementsByTagName('head')[0];
            x.appendChild(s);
        }

        function script(url) {
            var s = document.createElement('script');
            s.type = 'text/javascript';
            s.async = true;
            s.src = url;
            //s.defer = true;
            var x = document.getElementsByTagName('head')[0];
            x.appendChild(s);
        }


         (function () {
                stylesheet('https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css');
                stylesheet('https://fonts.googleapis.com/css?family=Roboto');
                stylesheet('https://fonts.googleapis.com/icon?family=Material+Icons');
                stylesheet('./templates/main/user-theme/tpl-files/material.act.css');
                stylesheet('plugins/dropzone/dropzone.css');
                stylesheet('plugins/stepper/stepper.min.css');
                stylesheet('./templates/main/user-theme/tpl-files/style.css');
                stylesheet('./templates/main/style/newprofile.css');
                stylesheet('plugins/getmdlselect/getmdl-select.min.css');       

                script('https://code.getmdl.io/1.3.0/material.min.js');
                script('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js');
                script('https://apis.google.com/js/api:client.js');
                script('https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBk99v0F4qkmvxifqOD48YktK-QO-3kopI');
                script('./templates/main/user-theme/javascript/google.js');
                script('plugins/getmdlselect/getmdl-select.min.js');
                script('./templates/main/user-theme/javascript/facebook.js');
                script('./templates/main/user-theme/javascript/newprofile.js');
                script('./templates/main/javascript/zipcode.js');
                script('plugins/stepper/v2/stepper.js');


         })();
 </script>

1 个答案:

答案 0 :(得分:0)

您必须通过.className而不是.style.className

来定义元素的类
i.className = 'material-icons';

&#13;
&#13;
var elements = document.body;

var i = document.createElement('i');
i.className = 'material-icons';
var text = document.createTextNode('check');
i.appendChild(text);

elements.appendChild(i);
&#13;
<head>
</head>
<body>
  <script>
      function stylesheet(url) {
            var s = document.createElement('link');
            s.rel = 'stylesheet';
            s.async = false;
            s.href = url;
            var x = document.getElementsByTagName('head')[0];
            x.appendChild(s);
        }

        function script(url) {
            var s = document.createElement('script');
            s.type = 'text/javascript';
            s.async = true;
            s.src = url;
            //s.defer = true;
            var x = document.getElementsByTagName('head')[0];
            x.appendChild(s);
        }


         (function () {
                stylesheet('https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css');
                stylesheet('https://fonts.googleapis.com/css?family=Roboto');
                stylesheet('https://fonts.googleapis.com/icon?family=Material+Icons');
                stylesheet('./templates/main/user-theme/tpl-files/material.act.css');
                stylesheet('plugins/dropzone/dropzone.css');
                stylesheet('plugins/stepper/stepper.min.css');
                stylesheet('./templates/main/user-theme/tpl-files/style.css');
                stylesheet('./templates/main/style/newprofile.css');
                stylesheet('plugins/getmdlselect/getmdl-select.min.css');       

                script('https://code.getmdl.io/1.3.0/material.min.js');
                script('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js');
                script('https://apis.google.com/js/api:client.js');
                script('https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBk99v0F4qkmvxifqOD48YktK-QO-3kopI');
                script('./templates/main/user-theme/javascript/google.js');
                script('plugins/getmdlselect/getmdl-select.min.js');
                script('./templates/main/user-theme/javascript/facebook.js');
                script('./templates/main/user-theme/javascript/newprofile.js');
                script('./templates/main/javascript/zipcode.js');
                script('plugins/stepper/v2/stepper.js');


         })();</script>
</body>
&#13;
&#13;
&#13;