gpt4 book ai didi

javascript - 提交前检查文本框

转载 作者:太空宇宙 更新时间:2023-11-04 15:15:14 25 4
gpt4 key购买 nike

如何在提交前检查文本框?

<form action='search.php' method='GET'>

<input type="text" id= "q" name="q" class='textbox' >

<input type="submit" id='submit' value="Search" class ='button' >

</form>

最佳答案

试试这个简单的 JavaScript 验证:

<html>
<head>
<script type="text/javascript">
function check()
{
var searchtext = document.getElementById("q").value;
if(searchtext=='')
{
alert('Enter any character');
return false;
}
}
</script>
</head>
<body>
<form action='search.php' method='GET' onSubmit="return check();">
<input type="text" id= "q" name="q" class='textbox' >
<input type="submit" id='submit' value="Search" class ='button' >
</form>
</body>
</html>

关于javascript - 提交前检查文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15997632/

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