繁体   English   中英

HTML5 onclick按钮不起作用

[英]HTML5 onclick button does not works

我有这个html文件,必须在onclick下调用一个函数,但是不执行任何操作,也不发出警报。 我不知道此按钮发生了什么。该按钮不起作用,是“ id = botonRegistro”(任何按钮确实起作用)。

<!DOCTYPE html>
<html>
    <head>
<!--        <script type="text/javascript" src="js/jquery-2.0.2.js"></script> -->
<!--        <script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script> -->
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" src="js/functions_v1.js"></script>
        <script type="text/javascript" src="js/objects_v1.js"></script>
        <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>KirolAPP</title>
    </head>
<body>
    <div data-role="page" id="registerPage">
        <div data-role="header" align="center">
            <img src="img/kirolLogo.png"> <br>
        </div>
        <div data-role="content" align="center" id="registerContent">
            <form id="formRegistro">
                <br> <input type="text" id="idNombreReg" style="border: 1;" placeholder="Nombre"><br>
                <input type="text" id="idSec" style="border: 1;" placeholder="1ºApellido"><br>
                <input type="text" id="idLast" style="border: 1;" placeholder="2ºApellido"><br>
                <input type="password" id="idClaveReg" style="border: 1; color: orange;" placeholder="Clave"><br>
                <input type="password" id="idClaveRegRep" style="border: 1; color: orange;" placeholder="Confirmar clave"><br>
                <input type="email" id="idEmail" style="border: 1;" placeholder="Email"><br>
                <button type="button" id="botonRegistro" onclick="alert('Registrado!')">Registrarse</button>
            </form>
        </div>
        <div  data-role="content" id="back" style="text-align: center; display: none" >
            <a href="index.html" id="botonBack">Volver</a>
        </div>
        <br>
    </div>

</body>
</html>

我尝试过

onclick="alert('hello');"

而且我认为onclick不需要前缀,所以...我不知道这段代码发生了什么,因为它不会调用javascript函数。

编辑:这是我的CSS

body{
    background-image: url("../img/fondoIndex.png");
    background-size: inherit                       
    background-repeat:   no-repeat;
    background-position: center center;
}

使用解决方案进行编辑:

我没有在default-src中添加“ inline-unsafe”,如下所示:

https://ssl.gstatic.com'unsafe-eval''unsafe-inline'; style-src'self''unsafe-inline'; media-src *“>

我不知道为什么,但是内容安全策略阻止了它。 当我删除此meta时,所有的作品:

<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标签更新为此:

<meta http-equiv="Content-Security-Policy"  content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *">

我在default-src指令中添加了'unsafe-inline' ,以允许onClick()执行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM