0

.js ファイルがあり、sweetalert を使用してユーザーにメッセージをスローしようとしています。さらに、sweetalert の .js ファイルと .css ファイルを .js ファイル内で動的にロードしたいと考えています。

 // Load script
 var filerefjs = document.createElement('script');
 filerefjs.setAttribute("type", "text/javascript");
 filerefjs.setAttribute("src", "../../rotateScreen/dist/sweetalert.min.js");

 // Load CSS file
 var filerefcss = document.createElement("link");
 filerefcss.setAttribute("rel", "stylesheet");
 filerefcss.setAttribute("type", "text/css");
 filerefcss.setAttribute("href", "../../rotateScreen/dist/sweetalert.css");

  if (window.innerHeight < window.innerWidth){ 

      window.onload = function(){
        document.getElementById('b6').onclick = function(){
           swal({title: "",   text: "Message", 
                imageUrl: "../../rotateScreen/example/images/rotate.png", confirmButtonText: "OK"});
        };
      } 

   } // if

エラーは発生しませんが、アラート ボックスが画面に表示されません。

4

1 に答える 1

0

あなたのコードは正しいように見えます(そこのウェブサイトによると)。実際に sweetalert.js ファイルを正しくリンクしていることを再確認してください。また、CHROMES 開発者ツールのコンソールを見て、エラーがないことを確認してください。リンクされていないファイルや不足しているファイルがある場合は表示されます。

このコードをテストしたところ、.js ファイル内で問題なく動作しました。

sweetAlert('error', "Enter A valid email please", 'error');
于 2015-07-18T09:15:11.180 に答える