javascript - 如果它不是表单,则在烧瓶中获取按钮?
问题描述
嗨,我正在尝试将葡萄酒保存在数据库中,并且我在这里有物化卡。因此,用户不必登录即可搜索葡萄酒,但当他们这样做时,它们会显示不同的葡萄酒。我正在尝试从当用户单击添加按钮时显示的那个。我不知道该怎么做。谢谢你的帮助。
这是我所有葡萄酒的展示模板
<div class="row">
{% for w in newList %}
<div class="col s6 m4">
<div style="height: 570px" class="card">
<!-- <a href="{{ url_for('login') }}" class="btn-floating halfway-fab waves-effect waves-light teal" style="float:right; margin: 15px"><i class="material-icons">add</i></a> -->
<button class="btn-floating halfway-fab waves-effect waves-light teal" type="submit" name="action">
<i class="material-icons right">add</i>
</button>
</div>
<div class="card-content">
<span style="color: black; font-size: 22px; font-weight:normal ; line-height: 1.1" class="card-title">{{ w['name'] }}</span>
<p><i class="material-icons">location_on</i> {{ w['region'] }}
</p>
<p> <i class="material-icons">attach_money</i> {{ w['price'] }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
路线
@app.route('/save/<string:id>',method=['GET','POST'])
@login_required
def save(id):
if current_user.is_authenticated:
# saveWine=UserChoice()
解决方案
Without a form, you would need to add an onClick() action on that button and configure an ajax request to call the route.
Without ajax, you'll need to create a form.
Read this to learn how you can implement ajax requests.
推荐阅读
- javascript - 使用 R 和 PhantomJS 抓取 Web Scraping 交互式地图(javascript)
- javascript - 多个动态生成的具有相同类名的元素的单击事件以隐藏和取消隐藏其他元素
- flutter - 将新项目添加到列表
- javascript - JS 承诺 - catch() 不返回任何内容
- locust - 如何格式化包含引号、逗号和大括号的表单数据
- python - 为什么pygame图标会变色?
- javascript - 当 offsetLeft 达到多个像素时如何控制台日志
- linux-kernel - KVM/QEMU 和客户操作系统如何处理页面错误
- angular - 无需重新加载页面的角度路由/切换组件
- python - 如何使用 selenium 与 tabindex = -1 交互表单