2017-03-19 11 views
-1

私はちょうどCordovaを使い始めましたが、この単純なクリックイベントがうまくいかない理由をすでに混乱させましたか?以下は私のindex.htmlファイルです。私はどこにでもバックグラウンドがなくてはならず、それをクリックして携帯電話で作業するのではなく、代わりにタップを使うことを読んだ。タップは何の違いもありませんでした。はCordovaと連携していませんか?

<!DOCTYPE html> 
<html> 
    <head> 
    <!-- 
     Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript. 
     For details, see http://go.microsoft.com/fwlink/?LinkID=617521 
    --> 
     <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> 

     <meta name="format-detection" content="telephone=no"> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 
     <title>Eventia</title> 

     <link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
     <script src="//code.jquery.com/jquery-1.10.2.min.js"></script> 
     <script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 

    </head> 
    <body> 
     <script type="text/javascript"> 
      $(document).on("click", ".gg2", function() { 
       console.log('hello'); 
       $('.gg2').css('background-color', 'blue'); 
      }); 
     </script> 

     <div class="gg" style="background: none"> 
      <div class="gg2"> 
       hello world 
      </div> 
     </div> 

    </body> 
</html> 

答えて

0

この問題は、コルドバに関連していない、bodyタグを閉じる前にスクリプトを入れて、その準備ができてDOMのことができるようにすることができ、readyイベント

$(document).ready(function(){ 
    $(document).on("click", ".gg2", function() { 
     console.log('hello'); 
     $('.gg2').css('background-color', 'blue'); 
    }); 
    }); 
でスクリプトを囲みます
0

インラインJSのように見えます。 5〜6行目に貼り付けたコメントを慎重に読んでください。その原因を確認するには、Content-Security-Policy行をコメントアウトしてください。

関連する問題