Javascript Cordova iOS don';不响应触摸输入

Javascript Cordova iOS don';不响应触摸输入,javascript,ios,cordova,Javascript,Ios,Cordova,我已经在iOS上创建了一个Cordova应用程序,当我尝试按下模拟器或真实设备上的按钮时,应该会显示按钮已按下的警报。不幸的是什么也没发生,我也不太清楚为什么。一些代码: <html> <head> <!-- Customize this policy to fit your own app's needs. For more guidance, see: https://github.com/apache/cordova-plugi

我已经在iOS上创建了一个Cordova应用程序,当我尝试按下模拟器或真实设备上的按钮时,应该会显示按钮已按下的警报。不幸的是什么也没发生,我也不太清楚为什么。一些代码:

<html>
<head>
    <!--
    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">

    <title>Hello World</title>
</head>
<body>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
    document.addEventListener('deviceready', function(){alert('device ready');}, false);

    function showAlert(){
        alert("Button is pressed!");
    }

</script>

<h1>This is an app</h1>
<button onClick="showAlert()">Press me!</button>

</body>

你好,世界
addEventListener('deviceready',function(){alert('device ready');},false);
函数showAlert(){
警报(“按下按钮!”);
}
这是一个应用程序
按我!


有人能看出我是否犯了一个难以置信的愚蠢错误吗?

onClick
实际上需要是
onClick
。这会让你警觉,但只有当你抬起手指时,它才会变得迟钝。这是因为onclick通常用于计算机。对于使用cordova的ios,您可以使用
ontouchstart
如果您使用的是5.0.0或更高版本,则需要使用
白名单
系统。它涵盖了防止内联javascript工作的CSP(内容安全策略)

你的HTML元素
按我
有一个内联javascript元素。从Cordova 5.0.0开始,您不能使用该选项。此限制是新WebView库的一部分(iOS的UIWebview和WKWebview)

要在HTML中使用内联javascript,必须编写CSP异常。注意:这将使你的应用程序不安全。您可以按照下面的链接添加安全性

这是您的代码,请将其添加到
index.html

请注意,您的应用程序现在不安全。 保护应用程序的安全取决于您。 以下链接将帮助您了解所需内容:

祝您好运

两件事:1)使用dialogs插件获取警报>2)您必须等待文档加载完成,然后才能为
deviceready添加事件侦听器
>