2016-04-13 9 views
1

ボタンのonclickでJavaScript関数を呼び出そうとしています。しかし、それは動作していません。onclick関数呼び出しがapache cordova(バージョン6.1.1)で動作しない

私は

  1. sqliteのいくつかのコルドバのプラグインを使用しています
  2. ファイル
  3. ファイル転送
  4. DBCOPY
  5. ファイルパス

    <button onclick="testalert()"> test alert </button> <script> function testalert() { alert("alert is working"); } </script> 
    

のAndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?><manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.cordova.gkslapp" xmlns:android="http://schemas.android.com/apk/res/android"> 
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true"> 
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize"><intent-filter android:label="@string/launcher_name"> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> </manifest> 

答えて

0

ドキュメントオブジェクトの呼び出しでjQueryのデリゲート関数を使用しました。 コードを読みやすくするために、私たちはjs fillを作成しました。この関数はデリゲート関数しかありませんでした。

$(document).delegate(".cus-name", "click", showLoader);

ここshowLoaderは、いくつかの他のファイルにある関数です。デリゲート関数を使用する主な理由は、ページとページの一部を動的にロードするためです。

0

まず:コルドバ/ PhoneGapのプロジェクトでのJSの機能のすべては、第二次devicereadyイベント

後に実行する必要があります:あなたはjQueryのではなくclick機能を使用して使用しているので、

0
**index.html** 

<!DOCTYPE html> 
<html> 
    <head> 
     <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" /> 
     <script src="js/jquery-2.0.1.min.js"></script> 
     <script src="js/jquery.mobile-1.4.5.min.js"></script> 
     <!-- 
     Customize this policy to fit your own app's needs. For more guidance, see: 
      https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy 
     Some notes: 
      * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication 
      * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly 
      * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: 
       * Enable inline JS: add 'unsafe-inline' to default-src 
     --> 
     <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"> 


    </head> 
    <body > 



     <div id="target"> 
      Click here 
     </div> 




     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
    </body> 
</html> 



**index.js** 




$("#target").click(function() { 
    alert("Button Clicked"); 
}); 


Try this . 
+1

コードのみの回答については、[this](http://meta.stackoverflow.com/a/303605/4284627)を参照してください。 –

関連する問題