【发布时间】:2014-07-10 04:34:40
【问题描述】:
我正在使用这个"Fancy Slider" 插件,它基本上通过并排设置多个字段集来工作。由于每个字段集都是同一类的成员,因此我试图找到为每个表单添加清除按钮的最简单方法,并使用 jQuery 单独清除该特定表单中的输入字段。
我尝试使用.parent()、.parents() 和.closest() 来隔离用户正在处理的字段集,但没有成功。虽然我可以清除我正在处理的表单,但我最终会清除应用程序中每个字段集中的表单。我们经常使用 jQuery,所以我对此比较陌生。有任何想法吗?
jQuery
$('#clearButton').click(function() {
$(this).closest('fieldset').find('input:text').val('');
$('#Pensgc').attr('readonly', false);
});
剃须刀示例
<fieldset class="step">
<legend>Display Exceptions</legend>
<center>
<table id="ExceptionEditing">
<thead>
<tr>
<th>Exception Name</th>
<th>Starting Letter</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.ExceptionList.Count(); i++)
{
<tr id="@Model.ExceptionList[i].Id">
<td>
@Html.TextBoxFor(anything => Model.ExceptionList[i].ExceptionName, new {style = "width:300px;", @readonly = "readonly", maxlength=255 })
</td>
<td style="padding-left:30px;" class="EditStartingLetter">
@Html.TextBoxFor(anything => Model.ExceptionList[i].StartingLetter, new {style = "width:10px;", @readonly = "readonly", maxlength=1 })
</td>
<td style="padding-left:10px;">
<a href="#" class="editException">Edit</a>
</td>
<td style="padding-left:10px;">
<a href="#" class="deleteException">Delete</a>
</td>
</tr>
}
</tbody>
</table>
</center>
</fieldset>
<fieldset class="step">
<center>
<legend>Create Exception</legend>
<table>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.createExceptionName)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.createExceptionName, new { @class="AlphaNumOnly", maxlength=255 })
</div>
</td>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.createExceptionLetter)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.createExceptionLetter, new { @class="AlphaNumOnly", maxlength=1 })
</div>
</td>
</tr>
</table>
<button type="submit" class="submitButton">Submit</button>
<button type="submit" class="clearButton">Clear</button>
</center>
</fieldset>
编辑
这是一个有效的小提琴:http://jsfiddle.net/rZa2j/
【问题讨论】:
-
工作 jsfiddle 帮助我们帮助你
-
您的选择器与您的 HTML 相比是错误的。您正在使用
#clearButton这是一个 ID。在您的 HTML 中,您有class="clearButton"。 -
请把生成的html贴出来
-
@NealR Kyle 有答案。您正在按 ID 选择按钮,但它只有类。
-
@MikeBell - 刚刚添加了一个小提琴
标签: javascript jquery html