【发布时间】:2020-01-21 09:31:03
【问题描述】:
enter image description here我想在点击提交按钮后停留在表单视图中 我有一个带按钮的导航栏:
<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';
}
当有人点击按钮联系人时,请转到联系表。 点击提交后我想留在这个表单中,但是这段代码返回首页。
<!--/*************** 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>
【问题讨论】:
-
然后更改类型提交到按钮
-
@DevsiOdedra 那么表单可能会简单地停止做任何事情,目前似乎没有任何东西会在后台通过 AJAX 提交表单然后......
-
您想留在联系表格中并仍然发送表格,对吗?您需要使用 ajax 才能做到这一点。例如,将事件处理程序(在提交时)附加到表单并 preventDefault 事件以防止其默认行为(如返回主页)
-
@04FS你有什么解决办法吗?
标签: javascript php onclick submit