我在使用 Javascript/jQuery 清除表单时遇到问题
这是我的表单的定义方式 - 所有标签均按其应有的顺序关闭
<form id="eventpostform" name="eventpostform" method="post" action="post">
<table cellspacing="5px" style="margin-top: 10px;" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="180px">Event Name:</td>
<td width="210px"><a class="param_submit" style="width:86px;padding:6px 5px;margin-left:16px;" alt="" onclick="clearform();">Clear Form</a></td>
我尝试了以下方法,但没有成功:
$('#eventpostform').clearForm();
$('#eventpostform').resetForm();
$('#eventpostform').reset();
document.getElementById("eventpostform").reset();
前 2 个什么都不做,另外两个显示错误“Uncaught TypeError: Cannot call method 'reset' of null”
最佳答案
您可以使用表单对象上的重置方法来清除,而不是表单中的控件。您必须清除单个 html 元素,但清除它们的方法,例如要清除文本框,您可以将其值设置为 ''
或某个值。
重置表单中的所有控件
document.getElementById("eventpostform").reset();
清除个人控制
document.getElementById("textboxId").value = '';
使用 jQuery
$('#id').val('');
关于javascript - 结算表格问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15906603/