Javascript 无法重置我的HTML表单。什么都试过了
这是我的index.php代码Javascript 无法重置我的HTML表单。什么都试过了,javascript,php,html,Javascript,Php,Html,这是我的index.php代码 <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crosso
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
</head>
<body>
<?php session_start(); ?>
<?php if(isset($_SESSION['success']) && $_SESSION['success'] == 1) { ?>
<?php unset($_SESSION['success']); ?>
<div class="jumbotron text-center">
<h1>SUCCESS</h1>
<p>CONTACT CSV UPLOADED SUCCESSFULLY</p>
<p><a onclick="resetFormDetails();" href="">Go Back to Form</a></p>
</div>
<?php } else { ?>
<div class="jumbotron text-center">
<h1>CONTACT CSV UPLOAD</h1>
<p>On Submit it may take some time to update. Be Patience!</p>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<form id="contact-form" method="post" action="<?php echo 'upload.php'; ?>" enctype="multipart/form-data">
<div class="form-group">
<label for="contact-file">Upload Contact CSV</label>
<input name="contact_file" type="file" class="form-control-file" id="contact-file">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
</div>
<?php } ?>
</body>
<script>
function resetFormDetails() {
document.getElementById("contact-form").reset();
location.reload();
}
</script>
</html>
如果(window.history.replaceState){
window.history.replaceState(null,null,window.location.href);
}
成功
联系人CSV已成功上载
联系CSV上传
提交时可能需要一些时间进行更新。耐心点
您需要在提交到服务器后重置表单
如果您正在使用javascriptdocument.getElementById(“联系人表单”).reset()进行上传代码>
如果您是通过PHP进行的,请重新加载当前div,以便可以重置元素和值
你可以使用
form.reset()
功能。例如
函数resetForm(){
document.getElementById(“表单”).reset();
}
重置表单
此行为是由触发表单重新提交的位置重新加载引起的
解决方案将是,而不是:
location.reload();
使用:
有谁给过我-1没有完全读过我的问题。可能是@ZakariaChabihi的副本-你能检查一下我的代码吗。我已经试过了所有这些方法。。另外,我的代码中没有使用任何JQuery。您检查过我的代码吗?我已经把它放在那里了。但是没有运气检查我的返回表单锚onclick函数。
location.reload();
location.href = location.href;