我有一些代码可以在我的 IIS 5.1 开发箱上运行,但不能在我们的 IIS 6 生产服务器或 Firefox 中运行。我希望找到一些既适合我们的生产服务器又适合 Firefox 的代码。
这是发生的事情:
我有一个标签,最初应该显示为隐藏。我基本上使用这个标签来隐藏整行。
<label for="lbCloseDate" id="lbCloseDate" style="display:none">
<tr>
<td bordercolor="#f0f0e4" bgcolor="#f0f0e4"><h3>Close Date</h3></td>
</tr>
</label>
然后,我使用此 JavaScript 根据组合框的值取消隐藏它:
function statusShowHide()
{
var cboStatus = document.getElementById('cboStatus');
var lbCloseDate = document.getElementById('lbCloseDate');
if cboStatus = 'Closed')
{
lbCloseDate.style.display = "";
}
}
基本上,Firefox 和我们的产品服务器中发生的情况是标签/行不会隐藏。我没有错误;它只是没有像我想要的那样被隐藏。
我不需要使用标签来隐藏行...这只是我知道的唯一方法。因此,如果有更可取的东西可以实现相同的目标,我对此持开放态度。谢谢!
最佳答案
你缺少一个(这里 还有 == 用于比较,single = 用于分配。
if (cboStatus == 'Closed')
{
lbCloseDate.style.display = "";
}
它会进入这个区 block 吗?如果是这样,我建议更改 .display = "";到.display =“无”
您也可以只给您的 tr 一个 ID,并使用它来隐藏/显示行而不是标签。语法上会更正确。
编辑:
这是一个带有工作示例的 fiddle : http://jsfiddle.net/2FDPg/
这是基础知识:
function showOrHideRow(){
var theRow = document.getElementById('closeRow');
var theDropDown = document.getElementById('ChangeMe');
var theVal = theDropDown.options[theDropDown.selectedIndex].value;
if(theVal == 'Closed'){
theRow.style.display = 'none';
}
else{
theRow.style.display = 'block';
}
}
和 html:
<table>
<tr id="closeRow">
<td>Close Date:</td>
</tr>
<tr>
<td>another row</td>
</tr>
</table>
<select id="ChangeMe" onChange="showOrHideRow()">
<option value="">Change me</option>
<option value="Closed">Hide It</option>
<option value="Open">Don't Hide It</option>
</select>
关于javascript - Firefox/IE IIS 6 不支持在 Javascript/HTML 中隐藏标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7908116/