以下是html表单的代码,我正在努力提交它按预期工作的信息,但网页在提交后将输入信息保存在表单字段中。
我尝试在按钮刷新刷新时使用一对,但它不会将数据转发到parse.com上的数据库。
有人知道如何在表单提交后重置/刷新字段吗?
<div class="register span5 offset3">
<form id="signupForm">
<h2>Create an account <!--<span class="red"><strong>iAPP</strong></span>--></h2>
<input type="text" id="firstname" name="firstname" placeholder="first name">
<input type="text" id="lastname" name="lastname" placeholder="last name">
<input type="text" id="username" name="username" placeholder="username">
<input type="text" id="email" name="email" placeholder="Email address">
<input type="password" id="password" name="password" placeholder="password">
<button type="submit">SIGN UP</button>
</form>
</div>
</div>
<script type="text/javascript">
Parse.initialize("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1");
function signUp(e) {
e.preventDefault();
var firstname = document.getElementById("firstname").value;
var lastname = document.getElementById("lastname").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var email = document.getElementById("email").value;
var user = new Parse.User();
user.set("firstname", firstname);
user.set("lastname", lastname);
user.set("username", username);
user.set("password", password);
user.set("email", email);
// other fields can be set just like with Parse.Object
user.set("phone", "650-555-0000");
user.signUp(null, {
success: function (username) {
// Hooray! Let them use the app now.
},
error: function (username, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
}
);
}
document.getElementById('signupForm').addEventListener('submit', signUp);
</script>
答案 0 :(得分:0)
试试这段代码
<html>
<body>
<div class="register span5 offset3">
<form id="signupForm">
<h2>Create an account <!--<span
class="red"><strong>iAPP</strong></span>--></h2>
<input type="text" id="firstname" name="firstname" placeholder="first name">
<input type="text" id="lastname" name="lastname" placeholder="last name">
<input type="text" id="username" name="username" placeholder="username">
<input type="text" id="email" name="email" placeholder="Email address">
<input type="password" id="password" name="password"
placeholder="password">
<button type="submit">SIGN UP</button>
<button type="reset" value="Reset">Reset</button>
</form>
</div>
</div>
<script type="text/javascript">
Parse.initialize("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1");
function signUp(e) {
e.preventDefault();
var firstname = document.getElementById("firstname").value;
var lastname = document.getElementById("lastname").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var email = document.getElementById("email").value;
var user = new Parse.User();
user.set("firstname", firstname);
user.set("lastname", lastname);
user.set("username", username);
user.set("password", password);
user.set("email", email);
// other fields can be set just like with Parse.Object
user.set("phone", "650-555-0000");
user.signUp(null, {
success: function (username) {
// Hooray! Let them use the app now.
},
error: function (username, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
}
);
}
document.getElementById('signupForm').addEventListener('submit', signUp);
</script>
</body>
</html>
答案 1 :(得分:0)
如果在用户注册成功函数内部,只需清除表单中的所有输入字段?
实施例
success: function (username) {
document.getElementById("example").value = "";
}
或重新安置他们
实施例
success: function (username) {
location.assign("http://www.mypage.com/myhomepage");
}