我想清除表单中的所有输入和文本区域字段。当使用reset类的输入按钮时,它的工作原理如下:
$(".reset").bind("click", function() {
$("input[type=text], textarea").val("");
});
这将清除页面上的所有字段,而不仅仅是表单中的字段。我的选择器看起来像什么形式的实际重置按钮生活?
我想清除表单中的所有输入和文本区域字段。当使用reset类的输入按钮时,它的工作原理如下:
$(".reset").bind("click", function() {
$("input[type=text], textarea").val("");
});
这将清除页面上的所有字段,而不仅仅是表单中的字段。我的选择器看起来像什么形式的实际重置按钮生活?
当前回答
@using (Ajax.BeginForm("Create", "AcceptanceQualityDefect", new AjaxOptions()
{
OnSuccess = "ClearInput",
HttpMethod = "Post",
UpdateTargetId = "defect-list",
InsertionMode = InsertionMode.Replace
}, new { @id = "frmID" }))
frmID是表单的标识 我们调用JavaScript函数的名称为"ClearInput" <脚本type = " text / javascript”> 函数ClearInput() { //创建视图 $ (" # frmID ") . get (0) .reset (); } > < /脚本 如果这两项你都做对了,那么你将无法阻止它的工作……
其他回答
我在这里看到的代码和相关的SO问题似乎不完整。
重置表单意味着从HTML中设置原始值,所以我根据上面的代码将其放在一个小项目中:
$(':input', this)
.not(':button, :submit, :reset, :hidden')
.each(function(i,e) {
$(e).val($(e).attr('value') || '')
.prop('checked', false)
.prop('selected', false)
})
$('option[selected]', this).prop('selected', true)
$('input[checked]', this).prop('checked', true)
$('textarea', this).each(function(i,e) { $(e).val($(e).html()) })
如果我遗漏了什么或者有什么需要改进的地方,请告诉我。
我用这个:
$(".reset").click(function() {
$('input[type=text]').each(function(){
$(this).val('');
});
});
这是我的按钮:
<a href="#" class="reset">
<i class="fa fa-close"></i>
Reset
</a>
@using (Ajax.BeginForm("Create", "AcceptanceQualityDefect", new AjaxOptions()
{
OnSuccess = "ClearInput",
HttpMethod = "Post",
UpdateTargetId = "defect-list",
InsertionMode = InsertionMode.Replace
}, new { @id = "frmID" }))
frmID是表单的标识 我们调用JavaScript函数的名称为"ClearInput" <脚本type = " text / javascript”> 函数ClearInput() { //创建视图 $ (" # frmID ") . get (0) .reset (); } > < /脚本 如果这两项你都做对了,那么你将无法阻止它的工作……
$('#editPOIForm').each(function(){
this.reset();
});
其中editPOIForm是表单的id属性。
如果我想清除除accountType以外的所有字段,请使用以下方法
$q(':input','#myform').not('#accountType').val('').removeAttr('checked').removeAttr('selected');