【发布时间】:2021-09-02 06:33:49
【问题描述】:
我目前正在处理一个 HTML 表单(使用 pug 视图引擎构建它),我尝试在填写后在 ajax 请求中使用它。
在编辑我的输入元素后按 Enter 时,它似乎提交了表单(我想是发布请求?)。我想让 enter-press 事件(就像我的按钮一样)触发一个 jquery 函数。
表单构建如下:
form(class="form" action="")
div(class="form-group")
label(for="testid") Tickersymbol
input(name="symbol", type="text", class="form-control", id="testid", placeholder="Please enter the symbol")
div(class = "form-group")
button(class="btn btn-primary" id="getdata" type="button") Get Info
当前的 JQuery 代码:
// This does not work
$("#inputStocksymbol").trigger('click', function (){
console.log("Enter event should have happened.")
})
// This does work
$("#getquote").click( function () {
console.log("Button has been pressed")
})
对于如何实现这一点有什么建议吗?
谢谢!
【问题讨论】:
标签: javascript html jquery pug