以下是我试图完成的代码,当用户单击提交按钮时,我的 javascript 函数将其 id='contact_form' 的表单的文本字段中的所有值设置为 null 而不加载页面。请让我知道如何修改以下代码以完成我一直在尝试做的功能。谢谢!!
<script type='text/javascript'>
$(document).ready(function(){
$('#love').click(function(e) {
document.contact_form.name.value = '';
alert('aloha!!');
//stop the form from being submitted (not working fine)
e.preventDefault();
}
}
</script>
<form name='abc' action='' id='abc' >
<input type="submit" id='love' />
</form>
我也尝试了以下功能,它运行良好,但它并没有阻止页面加载
<script type='text/javascript'>
function js(){
document.contact_form.name.value = '';
//stop the form from being submitted (NOT WORKING!!)
preventDefault();
}
}
</script>