简体   繁体   English

未捕获的 ReferenceError:addRecord 未在 HTMLButtonElement.onclick 中定义

[英]Uncaught ReferenceError: addRecord is not defined at HTMLButtonElement.onclick

when i click on the add record button it doesn't work and then it gives me an uncaught reference error, but if i load one of the jquery https://code.jquery.com/jquery-3.4.1.min.js scripts in the browser, it shows the button working perfectly.当我点击添加记录按钮时它不起作用,然后它给了我一个未捕获的引用错误,但是如果我加载一个 jquery https://code.jquery.com/jquery-3.4.1.min.js浏览器中的脚本,它显示按钮工作正常。 any suggestions please?请问有什么建议吗?

base.html基本文件

<!DOCTYPE html >
{%load staticfiles%}
{% load crispy_forms_tags %}
<html>
<head>
    <meta charset="UTF-8">
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="{% static 'style.css' %}"/>
    <title>{% block title %}{% endblock %}</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

</head>
<body class="container-fluid">
<div class="row">
<div class="col-lg-12">

    {% block content %}
    {% endblock %}

</div>
</div>
</body>
</html>

okay.html好的.html

...
{% extends "s/base.html" %}
{% load staticfiles %}
{% block content %}

{% block s_base %}
{{ block.super }}
<script>
alert('Helloo');
function addRecord(){
    console.log('hhhffhgfhdf');
}
</script>
{% endblock %}
            <div> <a href="javascript:void(0);"  ><button type="button" class="btn btn-primary" onclick="addRecord();"> Add New Advert </button></a></div>


{% endblock %}

it seems like you don't want to use Jquery, I suppose.我想您似乎不想使用 Jquery。

In this case, you can add your script close to the tag and and call the addRecord function like:在这种情况下,您可以将脚本添加到标签附近并调用 addRecord 函数,例如:

window.onload = function(){
 var button = document.querySelector('button');

button.onclic k= function(e){
  e.preventDefault();
  addRecord()
}

}

There's several ways of doing it but this is just an idea.有几种方法可以做到,但这只是一个想法。 remember to remove the onclick attibute from your html button记得从你的 html 按钮中删除onclick属性

暂无
暂无

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

相关问题 未捕获的ReferenceError :(函数)未在HTMLButtonElement.onclick中定义 - Uncaught ReferenceError: (function) not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick中定义查找 - Uncaught ReferenceError: lookup is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:showCurrentPage 未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: showCurrentPage is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:在 HTMLButtonElement.onclick 中未定义 postAcmgForm - Uncaught ReferenceError: postAcmgForm is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:HTMLButtonElement.onclick中未定义submitToAPI - Uncaught ReferenceError: submitToAPI is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:id 未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: id is not defined at HTMLButtonElement.onclick Uncaught ReferenceError: (function) is not defined at HTMLButtonElement.onclick - Uncaught ReferenceError: (function) is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:getProduct 未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: getProduct is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:HTMLButtonElement.onclick中未定义checkin - Uncaught ReferenceError: checkin is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:变量未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: variable is not defined at HTMLButtonElement.onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM