Html 我的提交和清除按钮在我的表单中不起作用
您好,我对编码非常陌生,在处理一个项目时,我尝试使用提交和重置按钮创建一个表单,但在测试表单时,它在计算机或移动设备上不起作用。谢谢你看这个。 在这里输入代码Html 我的提交和清除按钮在我的表单中不起作用,html,css,forms,button,Html,Css,Forms,Button,您好,我对编码非常陌生,在处理一个项目时,我尝试使用提交和重置按钮创建一个表单,但在测试表单时,它在计算机或移动设备上不起作用。谢谢你看这个。 在这里输入代码 <form id="form" action="contactform.php" method="post"> <label for="topic">Message Topic: </label> <select name="topic">
<form id="form" action="contactform.php" method="post">
<label for="topic">Message Topic: </label>
<select name="topic">
<option value="Memberships">Memberships</option>
<option value="Careers">Careers</option>
<option value="Other">Other</option>
</select>
<br><br>
<label for="Name">Name: </label>
<br>
<input name="FName" id="firstname" type="text" placeholder="First" size="20" required>
<input name="LName" id="lastname" type="text" placeholder="Last" size="20" required>
<br><br>
<label for="email">Email: </label><br>
<input name="Email" id="email" type="email" size="25" required><br>
<label for="phone">Phone Number: </label><br>
<input name="Phone" id="phone" type="tel" size="12" required>
<br><br>
<label for="message">Enter a Message Here:</label>
<br>
<br><textarea name="messagebox" id="message"></textarea>
<br><br>
<input type="submit" id="submit" value="Submit"></button>
<input type="reset" id="clear" value="Clear"></button>
<br>
</form>
</div>
</body>
<script>
$(document).ready(function(){
$(#submit).on('click touch', function () {
alert("You are about to SUBMIT this form. Is that ok?");
});
});
</script>
信息主题:
会员资格
事业
其他
姓名:
电子邮件:
电话号码:
在此处输入消息:
$(文档).ready(函数(){
$(#提交)。在('点击触摸')上,功能(){
提醒(“您即将提交此表单。可以吗?”);
});
});
问题出在语法上。将其更改为:
<button type="submit" id="submit">Submit</button>
<button type="reset" id="clear">Clear</button>
提交
清楚的
或
谢谢
同样在提交和重置类型中,您使用的是
但收场是一件好事
将两者都更改为任意一个
或者
问题是您没有在$(#submit)中指定单引号或双引号。
将“#提交”更改为表单id,并将“点击”更改为“提交”
<script>
$(document).ready(function(){
$('#form').on('submit', function () {
alert("You are about to SUBMIT this form. Is that ok?");
return true;
});
});
</script>
$(文档).ready(函数(){
$('#form')。在('submit',函数(){
提醒(“您即将提交此表单。可以吗?”);
返回true;
});
});
您的代码中有几个问题
,首先因为您没有相应的开始标记,其次您不需要使用它们,因为您已经通过使用
元素实现了相同的目的<button type="button" id="submit">Submit</button>
<button type="button" id="clear">Clear</button>
$("#submit").on('click', function () {
提交
清楚的
$(“#提交”)。在('click',函数(){
而不是
<input type="submit" id="submit" value="Submit"></button>
<input type="reset" id="clear" value="Clear"></button>
$(#submit).on('click touch', function () {
$(#提交)。在('点击触摸')上,功能(){
在html中,你犯了一些错误,比如提交按钮,你从
开始,试图用
因此,将其替换为
<input type="submit" id="submit" value="Submit"/>
<input type="reset" id="clear" value="Clear"/>
标签{
字体大小:20px;
右边距:20px;
}
文本区
{
宽度:100%;
}
信息主题:
会员资格
事业
其他
姓名:
电邮:
电话号码:
在此处输入消息:
谢谢,但我仍然有同样的问题。我做了更改,但我的按钮仍然不起作用。@MarkyMathAstewartZamiar你说的什么不起作用?运行上面的代码片段,然后tryok,我想我已经解决了问题。上面的代码确实起作用,但当表单靠近页面左侧时,它就会停止工作。当我试着做表单{margin left:1400px;对于css它确实有效。但是当我试着将表单向左移动时,它会停止像表单{margin left:300px;我不确定发生了什么?@MarkyMarthaStewartZamiar我应该让它对齐吗?
<input type="submit" id="submit" value="Submit"></button>
<input type="reset" id="clear" value="Clear"></button>
$(#submit).on('click touch', function () {
<input type="submit" id="submit" value="Submit"/>
<input type="reset" id="clear" value="Clear"/>