gpt4 book ai didi

javascript - 如何通过按 Enter 或按提交按钮提交表单?

转载 作者:行者123 更新时间:2023-12-01 03:20:25 24 4
gpt4 key购买 nike

我已经创建了一个表单,但只有在按下“提交”按钮时它才会提交...如何才能使其在按下 Enter 键时也提交?这是我的表单代码:

<form method="POST" id="form01">
<textarea name="inputBox123" id="myTextarea" style="white-space:nowrap;">
</textarea>
<input type="button" value="Submeter" onclick="myFunction()" />
</form>

<script type="text/javascript">

function myFunction(val) {

var testThis = document.getElementById("myTextarea").value;

if ( testThis.indexOf("launch") > -1 ) {
window.location = 'http://www.cateto.weebly.com/benoit.html';
return false;


}

}
</script>

谢谢

汤姆

最佳答案

而不是使用 <input type="button" /> ,使用<input type="submit" />发送表格。

默认情况下,输入按钮应提交表单。

关于javascript - 如何通过按 Enter 或按提交按钮提交表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45255091/

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