簡體   English   中英

為什么我的JavaScript計算器不能與base.html一起使用?

[英]Why isn't my javascript calculator working with the base.html?

所以不久前,我做了一個JavaScript計算器,現在在另一個項目中重新使用它。 問題是,它甚至不再顯示在頁面上。 這是calc.html文件的代碼。

{% extends 'base.html' %}

{% block body %}

<div class="text-center">
    <h1>Calculator</h1>
</div>
<div id="JSCalc">
    <form name="calculator">
        <input type="text" name="answer"/>
        <br />
        <input type="button" value=" 7" onclick="calculator.answer.value += '7'"/>
        <input type="button" value=" 8" onclick="calculator.answer.value += '8'"/>
        <input type="button" value=" 9" onclick="calculator.answer.value += '9'"/>
        <input type="button" value=" *" onclick="calculator.answer.value += '*'"/>
        <br />
        <input type="button" value=" 4" onclick="calculator.answer.value += '4'"/>
        <input type="button" value=" 5" onclick="calculator.answer.value += '5'"/>
        <input type="button" value=" 6" onclick="calculator.answer.value += '6'"/>
        <input type="button" value=" -" onclick="calculator.answer.value += '-'"/>
        <br />
        <input type="button" value=" 1" onclick="calculator.answer.value += '1'"/>
        <input type="button" value=" 2" onclick="calculator.answer.value += '2'"/>
        <input type="button" value=" 3" onclick="calculator.answer.value += '3'"/>
        <input type="button" value=" +" onclick="calculator.answer.value += '+'"/>
        <br />
        <input type="button" value=" 0" onclick="calculator.answer.value += '0'"/>
        <input type="button" value=" C" onclick="calculator.answer.value = ''"/>
        <input type="button" value=" =" onclick="calculator.answer.value = eval(calculator.answer.value)"/>
        <input type="button" value=" /" onclick="calculator.answer.value += '/'"/>
        <br />
    </form>
</div>

{% endblock %}

這是它的擴展名base.html文件。 請注意,這不是我寫的,我只是想讓計算器使用它,而看不到是什么在阻止它。

<!DOCTYPE html>
{% load static %}
<html class="no-js" lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>
            {% if indexPage %}
                Sales Tracker
            {% else %}
                {% block title %}{% endblock %} &sdot; Sales Tracker
            {% endif %}
        </title>
        <link rel='stylesheet' href='{% static "css/foundation.min.css" %}'/>
        <link rel='stylesheet' href='{% static "css/app.css" %}'/>
    </head>
    <body>
        <!-- Top Nav Bar -->
        <div class="top-bar">
            <div class="top-bar-left">
                <input type="submit" class="blue" value="Calculator" onclick="window.open('http://localhost:8000/calc','_blank','height=425,width=425')" />
                <a href="/">Sales Tracker</a>
                </div>
            <div class="top-bar-right">
                {% if user.is_authenticated %}
                    <a href="/account/">Account</a>
                    <a href="/logout/">Logout</a>
                {% else %}
                    <a href="/register/">Register</a>
                    <a href="/login/">Login</a>
                {% endif %}
            </div>
        </div>
        <!-- [END] Top Nav Bar -->

        {% block default_content %}{% endblock %}
        {% block content %}{% endblock %}
        <script src='{% static "js/vendor/jquery.js" %}'></script>
        <script src='{% static "js/vendor/what-input.js" %}'></script>
        <script src='{% static "js/vendor/foundation.min.js" %}'></script>
        <script src='{% static "js/app.js" %}'></script>
        {% block scripts %}{% endblock %}
    </body>
</html>

您說您需要訪問:

http:// localhost:8000 / calc.html (calc.html)

好吧,您還沒有定義這個權利? 您正在嘗試訪問:

http:// localhost:8000 / calc (計算)

您的代碼:

<input type="submit" class="blue" value="Calculator" onclick="window.open('http://localhost:8000/calc','_blank','height=425,width=425')" />

嘗試這個 :

<input type="submit" class="blue" value="Calculator" onclick="window.open('http://localhost:8000/calc.html','_blank','height=425,width=425')" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM