【发布时间】:2014-03-22 17:25:38
【问题描述】:
我不确定是否有人可以帮助我解决这个问题,但我目前有一个带有 onchange 的 ,它在切换时显示 2 种不同的形式。问题是我在表单之外还有一个更新按钮,并且在表单更改时也尝试更改按钮。
下面是我的代码。谁能帮我解决这个问题。
JavaScript:
隐藏/显示
function changelocation(val) {
var id = val;
//alert(id);
if (id == '1') {
$('#tr_1').css('display', 'table-row');
$('#tr_2').css('display', 'none');
}
if (id == '2') {
$('#tr_2').css('display', 'table-row');
$('#tr_1').css('display', 'none');
}
}
在表单外显示保存按钮
$(文档).ready(函数 () { $("#location1_update").click(function () { $("#location1").submit(); }); });
$(document).ready(function () {
$("#location2_update").click(function () {
$("#location2").submit();
});
});
按钮
<input class="submit-button" type="submit" name="location1_update" value="Update">
<input class="submit-button" type="submit" name="location2_update" value="Update">
- 使用 smarty note - 这很好用。
<select class="selmenu-wo" name="company_locations" onChange="changelocation(this.value)">
<option value="1" selected="selected">{section name=r loop=$location1}{$location1[r].LOCATION}
{/section}</option>
<option value="2">{section name=q loop=$location2}{$location2[q].LOCATION} {/section}
</option>
</select>
表格。
<form action="" id="location1" name="location1" method="POST">
<table cellpadding="0" id="tr_1" cellspacing="0">
<tr> <td><b>Name</b></td>
<input name="test" type="text" value="Test data">
</td></tr>
</table>
</form>
<form action="" id="location2" name="location2" method="POST">
<table cellpadding="0" id="tr_2" style="display:none" cellspacing="0">
<tr> <td><b>Name</b></td>
<input name="test2" type="text" value="Test data">
</td></tr>
</table>
</form>
表单切换正常,但我希望它在切换时也显示按钮。 如果我为表单和按钮分配相同的 id,则只有按钮切换。
【问题讨论】:
-
为什么不在相应的表单中包含按钮?
-
您是否希望在选择的值为1时显示location1_update并隐藏位置2_update? span>
-
我不想将它包含在表单中,因为它看起来不太好,当我显示按钮时我还有另一个表。更像是在页面的标题处。
-
@user3401335 是的,我想在选择表单 1 时隐藏位置 2 按钮,并在选择表单 2 时隐藏位置 1
-
我不太了解...所以您有一个具有 2 个或多个值的“选择菜单”...当您选择其中一个值时,它应该出现一个或另一个表单,根据在“选择菜单”中选择的值...您能否更具体地了解按钮?