Internet Explorer不会在JavaScript中执行某些if-case

时间:2019-06-04 11:18:09

标签: javascript internet-explorer-11

我正在用xslt创建一个html文件。我有一些JavaScript代码可以过滤表的某些行。在Internet Explorer 11上,我的JavaScript的某些特定情况没有执行,我也不知道为什么,因为开发控制台中没有错误。 在下面,您可以看到一些JavaScript代码,其中包含已执行和未执行的if-case的命令。

如果我将if (i > 2 && modelRange.textContent != rows[i - 1].getElementsByTagName("td")[0].textContent) {更改为if ( i > 2),它将执行if-case。因此,.textContent.getElementsByTagName一定有问题,但我不知道为什么,而且我不知道如何更改它,因为没有错误,并且可以在Firefox上正常工作。

我还包括了console.log(rows)

JavaScript:

function test_internet_explorer() {

    // Variables
    var table, checkBox, filterCheckBox, filterDropDown, rows, cells, secret, modelRange, dropdown, rowCount;
    dropdown = document.getElementById('modelRangeDropdown');
    table = document.getElementById('myTable');
    rowCount = table.rows.length; 
    checkBox=document.getElementById('identicalSecrets');
    rows = table.getElementsByTagName("tr");    
    console.log(rows)       
    filterCheckBox = checkBox.checked; 
    filterDropDown = dropdown.value;
    var index = 0; 


    for (var i = 0; i < rows.length; i++) { 
        var row = rows[i];
        cells = row.getElementsByTagName("td"); 
        modelRange = cells[0] || null; 
        secret = cells[3]; 

        // does not execute
        if (i > 2 && modelRange.textContent != rows[i - 1].getElementsByTagName("td")[0].textContent) {
            rows[i - 1].getElementsByTagName("td")[2].firstChild.nodeValue = "-";
            alert('script loaded');
        }

        // does execute
        if (i === rowCount - 1) { 
            rows[i].getElementsByTagName("td")[2].firstChild.nodeValue = "-";
        }

        // does not execute
        if (i > 2 && modelRange.textContent === rows[i - 1].getElementsByTagName("td")[0].textContent) {
            rows[i - 1].getElementsByTagName("td")[2].firstChild.nodeValue = rows[i].getElementsByTagName("td")[1].textContent;
        }
    }

}

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
    <head><title>Secrets</title></head>

<body onload="test_internet_explorer();">

<table id="myTable">
        <colgroup>
            <col width="150" style="background-color:e2e2e2"></col>         
        </colgroup>
        <tr  style ="background-color:a5a5a5">
            <th rowspan="2">plane
                <select id="modelRangeDropdown" onchange="test_internet_explorer()">
                     <option selected="selected">All</option>
                     <xsl:for-each select="logstore/plane">
                        <option>
                         <xsl:value-of select="Name" />
                        </option>
                     </xsl:for-each>                    
                </select>                   
            </th>   
            <th colspan="2" width="330">date</th>
            <th rowspan="2">Secret
                <input type="checkbox" id="identicalSecrets" onchange="test_internet_explorer()"></input>
                <label for="identicalSecrets">hide identical secrets</label>
            </th>
        </tr>

        <tr>
            <th align="center" style="background-color:a5a5a5">begin</th>
            <th align="center" style="background-color:a5a5a5">end</th>
        </tr>
        <xsl:for-each select="logstore/plane/trigger">
            <tr>
                <td align="center"><xsl:value-of select="../Name"/></td>
                <td align="center"><xsl:value-of select="date"/></td>
                <td align="center"><xsl:value-of select="date"/></td>
                <td><xsl:value-of select="secret"/></td>
            </tr>
        </xsl:for-each>
    </table>    
    <script type="text/javascript" src="test_internet_explorer.js"></script>    
</body>
</html>
</xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

对于我来说,一种可能的解决方案是,如果使用namespace Microsoft.AspNetCore.Mvc { public class ActionContext { public ActionContext(); public ActionContext(ActionContext actionContext); public ActionContext(HttpContext httpContext, RouteData routeData, ActionDescriptor actionDescriptor); public ActionContext(HttpContext httpContext, RouteData routeData, ActionDescriptor actionDescriptor, ModelStateDictionary modelState); public ActionDescriptor ActionDescriptor { get; set; } public HttpContext HttpContext { get; set; } public ModelStateDictionary ModelState { get; } public RouteData RouteData { get; set; } } } 在IE11上出现问题,则使用innerText而不是textContent