gpt4 book ai didi

javascript - 输入键重新加载页面

转载 作者:行者123 更新时间:2023-11-28 05:07:13 24 4
gpt4 key购买 nike

按下 Enter 键或单击“info”按钮时,Meteor 模板会重新加载页面,而不是触发 footerInfo 方法的预期行为。
知道为什么以及如何在点击/按下按钮或按下 Enter 键时触发该方法吗?谢谢

Template.content.events({
'keypress input': function (evt, template) {
if (evt.which === 13) {
$( "form" ).submit();
}
},
'submit form': function (event) {
event.preventDefault();
footerInfo();
}
});

footerInfo = () => {
//do stuff
};
<head>
<title>myApp</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="main">
<div id="login-div">{{> loginButtons align='right'}}</div>
<div id="content">
<form>
<button type="submit" style="display:none"></button>
{{#if currentUser}}
{{#if isVerified}}
{{> content}}
{{> footer}}
{{else}}
<p>Check your email for your verification link!</p>
{{/if}}
{{/if}}
</form>
</div>
</div>
</body>

<template name="content">
<form>
<input type="text" id="plateNum">
{{> results}}
</form>
</template>

<template name="results">
<p id="result">{{{display.alert}}}</p>
</template>

<template name="footer">
<footer>
<button id="clear">CLEAR</button>
<button id="info">INFO</button>
</footer>
</template>

最佳答案

问题是因为您的代码中有两个 form 标记。您也不需要监听 Enter 键事件,默认情况下,当您按 Enter 键时将触发提交事件。要解决此问题,首先需要删除内容模板中的 form 标记:

<template name="content">
<input type="text" id="plateNum">
{{> results}}
</template>

删除content模板中的keypresssubmit事件监听器,并在中添加submit事件监听器正文模板:

Template.body.events({
'submit form': function (event) {
event.preventDefault();
footerInfo();
}
});

关于javascript - 输入键重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41646717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com