【发布时间】:2013-05-03 09:26:13
【问题描述】:
当我单击重置按钮时,我的工作代码可以重置我的表单。然而,当我的代码变长后,我意识到它不再起作用了。
<div id="labels">
<table class="config">
<thead>
<tr>
<th colspan="4"; style= "padding-bottom: 20px; color:#6666FF; text-align:left; font-size: 1.5em">Control Buttons Configuration</th>
</tr>
<tr>
<th>Index</th>
<th>Switch</th>
<th>Response Number</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<form id="configform" name= "input" action="#" method="get">
<tr>
<td style="text-align: center">1</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" value="" id="number_one"></td>
<td><input style="background: white; color: black;" type="text" id="label_one"></td>
</tr>
<tr>
<td style="text-align: center">2</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id = "number_two" value=""></td>
<td><input style="background: white; color: black;" type="text" id = "label_two"></td>
</tr>
<tr>
<td style="text-align: center">3</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id="number_three" value=""></td>
<td><input style="background: white; color: black;" type="text" id="label_three"></td>
</tr>
<tr>
<td style="text-align: center">4</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id="number_four" value=""></td>
<td><input style="background: white; color: black;" type="text" id="label_three"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="configsubmit" value="Submit"></td>
</tr>
<tr>
<td><input type="reset" id="configreset" value="Reset"></td>
</tr>
</form>
</tbody>
</table>
</div>
还有我的 jQuery:
$('#configreset').click(function(){
$('#configform')[0].reset();
});
为了使.reset() 方法起作用,我应该在我的代码中包含一些来源吗?以前我使用的是:
<script src="static/jquery.min.js"></script>
<script src="static/jquery.mobile-1.2.0.min.js"></script>
并且.reset() 方法有效。
目前我正在使用
<script src="static/jquery-1.9.1.min.js"></script>
<script src="static/jquery-migrate-1.1.1.min.js"></script>
<script src="static/jquery.mobile-1.3.1.min.js"></script>
这可能是原因之一吗?
【问题讨论】:
-
你能举一个不工作的例子吗?是否有任何字段被重置?
-
有点像这样,但在这里工作正常jsfiddle.net/chJ8B :( 可能是因为脚本的其他部分?但我只有一个表格
-
我的问题是是否没有任何字段被重置/有些正在工作
-
您的 HTML 无效。表单不能是 TBODY 元素的子元素,TR 也不能是 FORM 元素的子元素。将表格标签放在表格之外(即将表格放在表格中)。很可能表单被移到表格外,但表单控件留在单元格中,因此它们不再在表单中。
-
@RobG:好点!我会试试的。谢谢!如果我不回到这里获取我的小提琴链接,我可能会错过这个有用的评论:s
标签: javascript jquery forms reset