我认为我非常接近 - 但不完全在那里......简而言之:我试图显示表格的底部(步骤2),具体取决于表格顶部的输入字段中是否存在数据(步骤1)。我正在尝试通过 jQuery 使用 removeClass 来进行文档的初始加载和更改。
请注意:此处包含多个脚本 - 并非表明我缺乏经验,而是表明我一直在努力解决这个问题,这些是我的多次尝试...
<table>
<tr align="center">
<td colspan="2">
<hr>
</td>
</tr>
<tr id="Step1ID">
<td valign="middle">Step 1 Data:</td>
<td valign="middle">
<input type="text" id="Step1Data" name="Step1Data" size="8" maxlength="8" />
</td>
</tr>
<tr align="center">
<td colspan="2">
<hr>
</td>
</tr>
<tr id="Step2ID" class="hideS2">
<td>Step2 Data:</td>
<td>
<input type="text" id="Step2Data" name="Step2Data" size="8" maxlength="8" />
</td>
</tr>
<tr align="center">
<td colspan="2">
<hr>
</td>
</tr>
</table>
$(document).ready(function () {
var Step1Data = $("#Step1Data").val();
if (Step1Data === '') {} else {
$('tr').removeClass('hideS2');
}
$(document).on('change', '#Step1ID', function () {
var Step1Data = $.trim(("#Step1Data").val());
if (Step1Data === '') {} else {
$('tr').removeClass('hideS2');
}
});
$(body).on('change', '#Step1ID', function () {
var Step1Data = $.trim(("#Step1Data").val());
if (Step1Data === '') {} else {
$('tr').removeClass('hideS2');
}
});
$('#Step1ID').on('change', '#Step1Data', function () {
var Step1Data = $.trim(("#Step1Data").val());
if (Step1Data === '') {} else {
$('tr').removeClass('hideS2');
}
});
$("Step1Data").blur(function () {
var Step1Data = $.trim(("#Step1Data").val());
if (Step1Data === '') {} else {
$('tr').removeClass('hideS2');
}
});
$("Step1ID").focusout(function () {
var Step1Data = $.trim(("#Step1Data").val());
if (Step1Data === '') {} else {
$('tr').removeClass('hideS2');
}
});
});
.hideS2 {
display: none;
}