【问题标题】:JQuery CDN does not work, localfile cannot be found [duplicate]JQuery CDN不起作用,找不到本地文件[重复]
【发布时间】:2023-03-19 04:12:01
【问题描述】:

我正在尝试使用一些简单的 jquery 隐藏一个按钮。 我试图将 jquery.js 文件放在与 html 页面相同的文件夹中,但这会产生 404 错误,因为它正在服务器上而不是我的本地计算机上查找 jquery.js 文件。

我以为我会使用 CDN,但这又不起作用,在控制台中我没有看到任何对 CDN 的请求,就像我将它指定为本地文件时一样。

有人能指出我正确的方向吗?

<html>
<body>
    <script src="jquery.js"></script>
    <script>
    $("#vlan_text").hide();
    </script>
<div class="content-section">
    <!-- ## form method must be POST for button click action-->
   <form method="POST" action="">
    <div class="input-group mb-3">
        <div class="input-group-prepend" id="test">
            <span class="input-group-text">Gi1/0/</span>
        </div>        
        <input type="text" class="form-control" id="port_in" name="port_input" aria-label="Port Number">
    </div>
    <input class="btn btn-info" type="submit" id="run_int" name="sh_run_int" value="Show interface configuration">
    <div class="well">
      <!-- ## the <pre> tags specify preformatted text-->
      <pre> {{ show_run_int }} </pre>
    </div>
    <div class="input-group mb-3" id="vlan_div">
        <input type="text" class="form-control" id="vlan_text" name="vlan_input" aria-label="VLAN">
    </div>
    </div>
   </form>
<body>
</html>


【问题讨论】:

  • 尝试使用文件 public_html/something/something/jquery.js 的完整路径更新:您编写的脚本将在此时触发,因此您应该将其包装在 jQuery(document).ready(function (){ //脚本 });原因是该脚本触发时 DOM 尚未准备好

标签: python jquery flask


【解决方案1】:
  1. 确保标记文件 (HTML) 和 JQuery 位于同一目录中或具有正确的脚本路径。

  2. 你为什么不关闭body标签(也许问题是因为他)?

【讨论】:

  • 您好,感谢您的帮助!我添加了正确的路径并关闭了正文标签。现在它起作用了!再次感谢。
【解决方案2】:

试试下面的代码,确保你的 HTML 和 JQuery 两个文件都在同一个目录中。

<html>
<body>
<div class="content-section">
    <!-- ## form method must be POST for button click action-->
   <form method="POST" action="">
    <div class="input-group mb-3">
        <div class="input-group-prepend" id="test">
            <span class="input-group-text">Gi1/0/</span>
        </div>        
        <input type="text" class="form-control" id="port_in" name="port_input" aria-label="Port Number">
    </div>
    <input class="btn btn-info" type="submit" id="run_int" name="sh_run_int" value="Show interface configuration">
    <div class="well">
      <!-- ## the <pre> tags specify preformatted text-->
      <pre> {{ show_run_int }} </pre>
    </div>
    <div class="input-group mb-3" id="vlan_div">
        <input type="text" class="form-control" id="vlan_text" name="vlan_input" aria-label="VLAN">
    </div>
    </div>
   </form>
    <script src="jquery.js"></script>
    <script>
    $("#vlan_text").hide();
    </script>
<body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 2012-11-02
    • 2012-12-02
    • 2019-12-21
    • 2022-12-14
    相关资源
    最近更新 更多