JQuery 功能不适用于 Python 的 Bottle

JQuery function not working with Python's Bottle

我试图覆盖 HTML 表单中提交按钮的默认行为,以便能够在实际启动表单操作之前加载 JQuery 动画。 当我 运行 来自 IDE 的 HTML 文件时 JQuery 正确地 运行ning 但是当我从 bottle 框架加载它时它只是自动跳到表单提交。

这是我拥有的:

瓶子

@route('/')
def root():
    return template('output_template.html', results=False)

@route('/lookup', method='POST')
def lookup():
    '''

HTML

<form action="/lookup" method="post" class="col s6">
  <div class="row">
    <h4 class="left-align"> Property Search</h4>
    <div class="col s6">
      <div class="row">
        <div class="input-field col s12">
          <input name="POSTCODE" id="postcode" type="text" class="validate">
          <label for="postcode">Post code</label>
        </div>
      </div>
      <div class="row">
        <div class="input-field col s12">
          <button class="btn waves-effect waves" type="submit" id="submit">Submit</button>
          <button class="btn waves-effect waves  blue-grey" type="reset" value="Reset" id="reset">Reset</button>
        </div>
      </div>
    </div>
  </div>
</form>

JQUERY

$(document).ready(function(){
    $("form").submit(function(e){
        e.preventDefault();
        alert('Started Form Submission')
        $("#content").hide("slow");
        $("#loading").show();
        delay(4);
        $("form").submit();
    });
});

有什么错误的想法吗?

如果您的 JQuery 代码在自己的文件中,Bottle 很可能不知道如何提供它,因为您只有 '/' 和 [=13= 的路由].看看瓶子里的routing static files

from bottle import static_file
@route('/static/<filename>')
def server_static(filename):
    return static_file(filename, root='/path/to/your/static/files')

不要忘记相应地更改脚本在 HTML header 中的位置。

已解决:

Bottle 未在页面底部呈现 JQuery 脚本。我把它改成了头部,现在它可以正常工作了。 谢谢一个