[英]Uncaught ReferenceError: (function) not defined at HTMLButtonElement.onclick
[英]Uncaught ReferenceError: addRecord is not defined at HTMLButtonElement.onclick
當我點擊添加記錄按鈕時它不起作用,然后它給了我一個未捕獲的引用錯誤,但是如果我加載一個 jquery https://code.jquery.com/jquery-3.4.1.min.js瀏覽器中的腳本,它顯示按鈕工作正常。 請問有什么建議嗎?
基本文件
<!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>
好的.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 %}
我想您似乎不想使用 Jquery。
在這種情況下,您可以將腳本添加到標簽附近並調用 addRecord 函數,例如:
window.onload = function(){
var button = document.querySelector('button');
button.onclic k= function(e){
e.preventDefault();
addRecord()
}
}
有幾種方法可以做到,但這只是一個想法。 記得從你的 html 按鈕中刪除onclick
屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.