0

我已经到处搜索试图弄清楚这一点,但似乎无法解决。我的 javascript 代码适用于 Firefox,但不适用于 IE8。任何想法为什么?

文档类型:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Javascript:

<script language="javascript">
function toggle() {
    document.getElementById('togglefield').style.display = "table-row";
    var offertype = document.getElementById('offertype1fsa').value;
    if (offertype === "SIF" || offertype === "") {
        document.getElementById('togglefield').style.display = "table-row";
    }
    else {
        document.getElementById('togglefield').style.display = "none";
    }
}
</script>

HTML:

<table>
    <tr>
        <td class="label" align="right">
            Offer Type
        </td>
        <td class="field" align="left">
      <select name="offertype1fsa" class="select" id="offertype1fsa" onchange="toggle();" >
        <option value=""></option>
        <option value="PIF">PIF</option>
        <option value="SIF">SIF</option>
      </select>               
        </td>
    </tr>

    <tr id="togglefield">
        <td class="label" align="right">
            Amount (if SIF)
        </td>
        <td class="field" align="left">
           <input type="text" name="sifamt1fsa" id="sifamt1fsa" />  
        </td>
    </tr>
</table>

谢谢!

4

2 回答 2

1

http://www.w3schools.com/cssref/pr_class_display.asp

注意:值“inline-table”、“table”、“table-caption”、“table-cell”、“table-column”、“table-column-group”、“table-row”、“table-row” -group”和“inherit”在 IE7 及更早版本中不受支持。IE8 需要一个!DOCTYPE。IE9 支持这些值。

于 2012-05-24T20:36:49.750 回答
0

试试这个DEMO

<script language="javascript">
function toggle(elem) {
    var offertype = elem.value;
    document.getElementById('togglefield').style.display =
        (offertype === "SIF" || offertype === "")? "":"none";
}
</script>
.
.
.

      <select name="offertype1fsa" class="select" id="offertype1fsa" onchange="toggle(this);" >
于 2012-05-24T20:37:40.060 回答