如何在此代码中使用javascript清除输入标记? 我已经测试了许多方法,但不能。
<div id="center">
<p id="alert">FILL FIELDS</p>
<input id="name"/>
<input id="family"/><br />
<button onclick="SaveData()" type="submit">INSERT</button>
</div>
<script>
function SaveData() {
var name = $('#name').val();
var family = $('#family').val();
$.ajax({
type: "POST",
url: "server.php?p=add",
data: "fn="+name+"&ln="+family,
success: function(msg){
document.getElementById('alert').innerHTML = "SUCCESS SAVE";
}
});
}
</script>
答案 0 :(得分:2)
要清除name
输入,可以使用jquery .val()
函数重置为空字符串:
$('#name').val('');
答案 1 :(得分:1)
是的,在您的成功函数中执行此操作:
success: function(msg){
document.getElementById('alert').innerHTML = "SUCCESS SAVE";
$('#name').val(''); // set the value to blank with empty quotes
$('#family').val('');
}