我有以下 HTML 代码,我想用类 editfield 和 editfieldlink 链接隐藏 div,并用类值显示 div。我尝试遵循 jQuery 代码,但它对我不起作用,但如果我像这样隐藏父级,这很好用:$(this).closest('div.editfield').parent().hide();
<tr class="row-fluid settingsrow">
<td class="span2">
<strong>Name</strong>
</td>
<td class="span8">
<div class="value">ALI ASAD</div>
<div class="editfield">
<form class="form-vertical">
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="firstname" id="firstname" placeholder="Ali">
</div>
</div>
<div class="control-group">
<label class="control-label">Last Name</label>
<div class="controls">
<input type="text" name="lastname" placeholder="Asad">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary btn-mini">Save Changes</button>
<button class="btn btn-inverse btn-mini cancelactionsettings">Cancel</button>
</div>
</div>
</form>
</div>
</td>
<td class="span1"><a href="#" class="editfieldlink" style="text-decoration:none"><small>Edit</small></a></td>
</tr>
我的 JavaScript 是这样的:
$(document).ready(function(e)
{
$('#settingseditor .cancelactionsettings').click(function(event)
{
event.preventDefault();
$(this).closest('div.editfield').hide();
$(this).closest('div.value').show();
$(this).closest('a.editfieldlink').hide();
});
});