在Firefox中运行的Javascript而不是IE ...为什么?

时间:2012-05-24 20:32:30

标签: javascript internet-explorer firefox

我已经搜遍了所有人,试图找出这个,但似乎无法。我的javascript代码适用于Firefox,但不适用于IE8。有什么想法吗?

DOCTYPE:

 <!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>

谢谢!

2 个答案:

答案 0 :(得分:1)

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

  

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

答案 1 :(得分: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);" >