Javascript “提交”按钮单击后保持在表单中
单击提交按钮后,我想留在表单视图中 我有一个带有按钮的导航栏:Javascript “提交”按钮单击后保持在表单中,javascript,php,onclick,submit,Javascript,Php,Onclick,Submit,单击提交按钮后,我想留在表单视图中 我有一个带有按钮的导航栏: <div class="bar blueGrey"> <button class="bar-item button tablink orange" onclick="openNavBarChoise(event,'HomePage')">Home</button> <button class="bar-item button tablink" onclick="openNavBarC
<div class="bar blueGrey">
<button class="bar-item button tablink orange" onclick="openNavBarChoise(event,'HomePage')">Home</button>
<button class="bar-item button tablink" onclick="openNavBarChoise(event,'CVsPage')">CV</button>
<button class="bar-item button tablink" onclick="openNavBarChoise(event,'ContactPage')">Contact</button>
</div>
家
个人简历
接触
Javascript代码:
function openNavBarChoise(evt, choiceName) {
var i, x, tablinks;
x = document.getElementsByClassName('choice');
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none';
}
tablinks = document.getElementsByClassName('tablink');
for (i = 0; i < x.length; i++) {
tablinks[i].className = tablinks[i].className.replace(' orange', '');
}
document.getElementById(choiceName).style.display = 'block';
evt.currentTarget.className += ' orange';
}
函数openNavBarChoise(evt,choiceName){
变量i,x,t;
x=document.getElementsByClassName('choice');
对于(i=0;i
当有人点击“联系人”按钮时,转到“联系人”窗体单击提交后,我希望留在该表单中,但此代码返回主页
<!--/*************** Begin Contact Page ***************/-->
<div id="ContactPage" class="container border choice" style="display:none">
<div class="panelChristos00">
<div class="ImgFPanel">
<img class="ImgPP" id="imgJob" src="Icons\contactSupport.png" alt="contactSupport" width="80px">
</div>
<div id="ergasia" class="firstLine">
<h2>Form</h2>
</div>
<div class="container">
<form id="form0" method="post" >
<div class="requiredM00">
<p style="color:red"><?php echo $requiredMessage;?></p><p style="color:blue"><?php echo $completeMessage;?></p>
</div>
<label for="name">Name <span class="error" style="color:red">*<?php echo $nameErr;?></span></label>
<input type="text" name="name" value="<?php echo $name;?>">
<label for="email">Email <span class="error" style="color:red">* <?php echo $emailErr;?></span></label>
<input type="text" name="email" value="<?php echo $email;?>">
<label for="phone">Phone <span class="error" style="color:blue"> <?php echo $phoneErr;?></span></label>
<input type="text" name="phone" value="<?php echo $phone;?>">
<label for="subject">Message <span class="error" style="color:red">*<?php echo $subjectErr;?></span></label>
<textarea id="subject" name="subject" style="height:200px" ><?php echo $subject; ?></textarea>
<input type="submit" value="Send">
</form>
</div>
</div>
</div>
形式
名字*
默认情况下,表单提交按钮将表单提交到自身以停止此操作。请在表单提交按钮上使用evt.preventdefault()您希望保留在联系人表单上并仍发送表单,对吗?您需要使用ajax才能做到这一点
将事件处理程序(提交时)附加到表单并防止默认事件以防止其默认行为(如返回主页)
你可以这样做,它会带你去你想要的新标签
<form action="your file name">
<input type="text">
<input onclick="e.preventDefault()" type="submit" formtarget="_blank">
</form>
然后更改类型提交到button@DevsiOdedra然后表单可能会停止做任何事情,目前似乎没有任何东西会在后台通过AJAX提交表单……你想留在联系人表单上,仍然发送表单,对吗?您需要使用ajax才能做到这一点。例如,将事件处理程序(提交时)附加到表单并防止默认事件,以防止其默认行为(如返回主页)@04FS您有任何解决方案吗?谢谢!我在idex.php文件中添加了这段代码,并用form0修改了myForm,用index.php修改了server.php。我也有同样的问题。我想用php调用的结果保持表单状态。表单的Php代码在同一个文件中。No。我将这段代码插入到我的文件index.php中,index.php是表单和php代码。你能帮我更多吗?如何使你的代码适应我的代码。谢谢。当我按下“发送”按钮时,什么也不做。我还添加了一个图像,谁能更好地描述我想做的事情。谢谢。如何在我的代码中使用它?当按下Send时,保持在这个表单中并运行php代码。您也可以像这样向表单标签添加目标属性,我不想要新标签。我希望保持在同一个选项卡中,显示我的php代码的结果。然后删除目标AttributeAnks。你能看看我的jpeg吗?他们描述了我想做什么。然后你必须通过按钮上的事件监听器提交表单,调用api并通过该按钮提交表单。为此,使用ajax或任何其他库阅读本文,然后你不必在表单中使用操作我不知道php,但在javascript fetch()中使用是为了看这段视频这可能会帮助你音质不好,我为你找到的一切
<form action="your file name">
<input type="text">
<input onclick="e.preventDefault()" type="submit" formtarget="_blank">
</form>