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

标签 javascript html css

我有以下代码。 “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/

相关文章:

html - 将 mvc 存储库获取的数据定位到 View 中(MVC4 Web)

javascript - 支付成功页面AngularJS

jquery - Opera 和 IE 中的 CSS 动画

image - 在圆形图像顶部带有边框的圆形图像 css

html - 使用 Bootstrap 通过响应式设计将页脚保持在底部

javascript - 如何从样式标签获取 CSS 属性值?

javascript - 如何克隆 img src 属性中的 url 参数值?

javascript - 重复单击按钮时防止再次加载标签图像

javascript - 如何检测浏览器插件?

javascript - 如何向视频js播放器添加自定义按钮