gpt4 book ai didi

javascript - 显示 block 和无正在更改表格缩进

转载 作者:行者123 更新时间:2023-11-30 15:56:20 25 4
gpt4 key购买 nike

我有以下代码。 “With Inventory Data”行可见性取决于我们在“产品类型”下拉列表中选择的内容。如果我们从下拉列表中选择 Linux,“With Inventory Data”行将被隐藏。在下拉列表中将其改回 Windows 会导致显示“With Inventory Data”行。但是这里是,否单选按钮位于文本“With Inventory Data”下方。这需要按照页面加载时的位置进行定位。请帮忙

var flag = 1;
function showHide() {

if (flag == 1) {
document.getElementById('warning').style.display = "none";
document.getElementById('inventoryCol1').style.display = "none";
document.getElementById('inventoryCol2').style.display = "none";
flag=0;

}
else {
document.getElementById('warning').style.display = "block";
document.getElementById('inventoryCol1').style.display = "block";
document.getElementById('inventoryCol2').style.display = "block";
flag=1;
}
}
function warningDisplay(myRadio) {
if(myRadio.value == "yes") {
document.getElementById('warning').innerHTML = "Target Build # should be \"55\" branch and above to select Inventory Data";
}
else {
document.getElementById('warning').innerHTML = "";
}
}
<html>
<body style="background-color:green">
<table>

<tr>
<td><label style="color: white; text-align: left;" id="osTypelable"><b>Product Type</b>&nbsp;&nbsp;</label></td>
<td><select style="width:205px; height:25px" id="osTypeDropdown" onChange="showHide()" >
<option value="win">Windows</option>
<option value="lin">Linux</option>
</select>
</td>
</tr>

<td style="color: white;text-align: left; " id="inventoryCol1"><label ><b>With Inventory Data</b>&nbsp;&nbsp;</label></td>
<td style="color: white;font-size:13px;font-weight: bold;" width=200 id="inventoryCol2">
<label style="display:inline-block;"><input type="radio" value="no" onClick="warningDisplay(this)" name="inv"/>&nbsp;No &nbsp; &nbsp; &nbsp; </label>
<label style="display:inline-block;"><input type="radio" value="yes" onClick="warningDisplay(this)" name="inv"/>&nbsp;Yes</label>
</td>
</tr>
<tr>
<td colspan="2"><b style="color: #DC143C;font-size:13; float:right" id="warning"> </b> </td>
</tr>

<tr>
<td colspan='2' align="center"><input name="submit"
type="submit" class="login" value="Submit"></td>
</tr>
</table>
</body>
</html>

最佳答案

<td>有初始display: table-cell

var flag = 1;
function showHide() {

if (flag == 1) {
document.getElementById('warning').style.display = "none";
document.getElementById('inventoryCol1').style.display = "none";
document.getElementById('inventoryCol2').style.display = "none";
flag=0;

}
else {
document.getElementById('warning').style.display = "block";
document.getElementById('inventoryCol1').style.display = "table-cell";
document.getElementById('inventoryCol2').style.display = "table-cell";
flag=1;
}
}
function warningDisplay(myRadio) {
if(myRadio.value == "yes") {
document.getElementById('warning').innerHTML = "Target Build # should be \"55\" branch and above to select Inventory Data";
}
else {
document.getElementById('warning').innerHTML = "";
}
}
<html>
<body style="background-color:green">
<table>

<tr>
<td><label style="color: white; text-align: left;" id="osTypelable"><b>Product Type</b>&nbsp;&nbsp;</label></td>
<td><select style="width:205px; height:25px" id="osTypeDropdown" onChange="showHide()" >
<option value="win">Windows</option>
<option value="lin">Linux</option>
</select>
</td>
</tr>
<tr>
<td style="color: white;text-align: left; " id="inventoryCol1"><label ><b>With Inventory Data</b>&nbsp;&nbsp;</label></td>
<td style="color: white;font-size:13px;font-weight: bold;" width=200 id="inventoryCol2">
<label style="display:inline-block;"><input type="radio" value="no" onClick="warningDisplay(this)" name="inv"/>&nbsp;No &nbsp; &nbsp; &nbsp; </label>
<label style="display:inline-block;"><input type="radio" value="yes" onClick="warningDisplay(this)" name="inv"/>&nbsp;Yes</label>
</td>
</tr>
<tr>
<td colspan="2"><b style="color: #DC143C;font-size:13; float:right" id="warning"> </b> </td>
</tr>

<tr>
<td colspan='2' align="center"><input name="submit"
type="submit" class="login" value="Submit"></td>
</tr>
</table>
</body>
</html>

关于javascript - 显示 block 和无正在更改表格缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38474152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com