簡體   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