gpt4 book ai didi

javascript - 提交表单后运行函数

转载 作者:行者123 更新时间:2023-11-28 11:01:43 25 4
gpt4 key购买 nike

我有一个 HTML 表单,该表单是通过 JavaScript 函数提交的。我想在提交表单时禁用该字段。我尝试过这个,但我不会工作。

<html>
<body>

<form id="my_form" method="GET">
<div class="naam-speeltijd-timer">
<div class="naam-overigetijd">

<div class="settime">
<div class="tekst">selecteer het aantal minuten:</div>
<div class="inputfield"><input type="time" name="usr_time" id="usr_time" />
</div>
</div>

</div>

<div class="settime-activeerbutton">

<div class="submit">
<a href="javascript:postform()" class="button blue"><div class="light">
</div>start timer</a>
</div>
</div>
</div>
</form>

<script type="text/javascript">
function postform( )
{
document.getElementById("usr_time").disabled = true;
document.getElementById('my_form').submit() ;
};
</script>
</body>
</html>

最佳答案

你不能使用onclick而不是href这样的东西吗:

<html>
<body>

<form id="my_form" method="GET">
<div class="naam-speeltijd-timer">
<div class="naam-overigetijd">

<div class="settime">
<div class="tekst">selecteer het aantal minuten:</div>
<div class="inputfield"><input type="time" name="usr_time" id="usr_time" />
</div>
</div>

</div>

<div class="settime-activeerbutton">

<div class="submit">
<a href="#" onclick="postform(this);" class="button blue"><div class="light">
</div>start timer</a>
</div>
</div>
</div>
</form>

<script type="text/javascript">
function postform(link)
{
alert("click");
link.onclick = function(event)
{
event.preventDefault();
}
document.getElementById('my_form').submit() ;
};
</script>
</body>
</html>

关于javascript - 提交表单后运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41467233/

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