确认确认

时间:2016-12-23 03:36:48

标签: javascript html

我做错了什么?我在控制台中收到错误:

  

未捕获的ReferenceError:未定义myRemove       在HTMLAnchorElement.onclick((index):20)

<script> 
function myRemove() {
    var r = confirm("Are you sure you want to delete your account?");
} else {
    // do nothing
    if (r == true) {
        document.cookie = "username=; expires=Thu, 01 Jan 2000 00:00:00 GMT";
        var r = confirm("Your account has been removed/deleted. Keep in mind, you must have an active account to use our internet services. Do you want to register again?");
        if (r == true) {
            window.location.href = "http://EXAMPLE.COM";
        }
    } else {
        alert("Alright, you decided to stay on this page and to not re-register.");
    } 

这是按钮的代码:

<a value="Remove account" onclick="myRemove()" on class="btn">Remove Your Account</a>

1 个答案:

答案 0 :(得分:0)

脚本有语法错误,因此未定义myRemove。

请参阅以下代码:

<script>
function myRemove() {
    var r = confirm("Are you sure you want to delete your account?");
    if (r == true) {
        document.cookie = "username=; expires=Thu, 01 Jan 2000 00:00:00 GMT";
        var r = confirm("Your account has been removed/deleted. Keep in mind, you must have an active account to use our internet services. Do you want to register again?");
        if (r == true) {
           window.location.href = "http://EXAMPLE.COM";
        } else {
           // do nothing
        }
    } else {
       alert("Alright, you decided to stay on this page and to not re-register.");
    }
}
</script>