Javascript仅在从直接HTML文件运行时有效

时间:2019-02-08 16:12:21

标签: javascript java html flask

我正在尝试使用脚本'index.html'运行html文件,当我使用CMD + I在Flask上直接运行它(从templates文件夹)时,它将运行并且脚本可以运行。但是,当我使用approute()将位置定向到“ index.html”时,javascript似乎根本无法运行。

index.html(位于模板文件夹中):

{% extends "layout.html" %}
{% block content %}
<doctype html>
<html class="no-js" lang="">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="apple-touch-icon" href="apple-touch-icon.png">
    <!-- Place favicon.ico in the root directory -->
</head>

<body>
    <interaction-viewer accession="P31749"></interaction-viewer>

    <!-- Required for IE11 -->
    <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js" defer></script>
    <!-- Web component polyfill (only loads what it needs) -->
    <script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs/webcomponents-lite.js" charset="utf-8" defer></script>
    <!-- Required to polyfill modern browsers as code is ES5 for IE... -->
    <script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js" charset="utf-8"
        defer></script>
    <script src="https://cdn.jsdelivr.net/npm/whatwg-fetch/fetch.min.js" charset="utf-8" defer></script>

    <script src="dist/interaction-viewer.js" charset="utf-8" defer></script>
    <script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="
        crossorigin="anonymous"></script>
    <script type="text/javascript">
        $('.accession-selector').change(function () {
            updateAccession(this.value);
        });
        var updateAccession = function (accession) {
            document.querySelector("interaction-viewer").setAttribute('accession',
                accession);
        };
    </script>
</body>

</html>
{% endblock %}

main.py:

@app.route("/int")
def intviewer():
    return render_template("index.html")

0 个答案:

没有答案