cordova javascript显示未捕获的TypeError:无法读取属性

cordova javascript显示未捕获的TypeError:无法读取属性,javascript,jquery,html,cordova,phonegap,Javascript,Jquery,Html,Cordova,Phonegap,我正在开发cordova应用程序。在这个应用程序中,我正在呼叫一个网站。网页正在正确访问。网页上有一个a按钮。我想在按钮单击时显示警报。网页按钮代码如下所示。在web中,没有定义按钮单击 <p><a class="btn btn-primary btn-lg">Take Picture &raquo;</a></p> 运行此代码时,它会显示 Uncaught TypeError:无法读取未定义的属性'addEventListener',来

我正在开发cordova应用程序。在这个应用程序中,我正在呼叫一个网站。网页正在正确访问。网页上有一个a按钮。我想在按钮单击时显示警报。网页按钮代码如下所示。在web中,没有定义按钮单击

<p><a class="btn btn-primary btn-lg">Take Picture &raquo;</a></p>
运行此代码时,它会显示
Uncaught TypeError:无法读取未定义的属性'addEventListener',来源:file:///android_asset/www/js/index.js


我不知道如何解决这个问题。请帮助我。

你在哪里包含了这个脚本,
。它在你的
js
文件之前吗?我的项目中看不到cordova.js文件。当我在cordova中创建一个新项目时,cordova.js看不到。不。你必须添加这个脚本。在构建时将生成该文件。然后tak它应该可以工作。它已经添加到index.html中
var app = {
    // Application Constructor
    initialize: function () {
        this.bindEvents();
    },
    bindEvents: function () {
        document.addEventListener('deviceready', this.onDeviceReady, false);        
    },
    onDeviceReady: function () {
    app.receivedEvent('deviceready');
    // Here, we redirect to the web site.
    var targetUrl = "http://mysite/mypage.php/";
    var bkpLink = document.getElementById("bkpLink");
    bkpLink.setAttribute("href", targetUrl);
    bkpLink.text = targetUrl;
    window.location.replace(targetUrl);
    //I want to call a alert when button click      
    document.getElementsByClassName('btn-lg')[0].addEventListener('click', (function(i) {
    return function() {
        alert("okkkkkkkkkk");
    };
    })(i), false);  

    },
    // Note: This code is taken from the Cordova CLI template.
    receivedEvent: function (id) {
    }

};
app.initialize();