javascript - children.innerText 在 Firefox 中不起作用

标签 javascript jquery firefox

<分区>

我有一个这样的 html:

<div class="tree" id="divTreeViewIncomeDetails" style="height: auto;">
            <li><span class="fa fa-folder-open highlight" id="3" onmouseover="visibleLink('3', 'Incomes', '0')" onmouseout="hideLink('3')"><span onclick="GetTreeViewChartOfAccountsByParam('3', 'Incomes')">Incomes </span><span class="closingbalance">INR 50.00Dr </span></span>
                <ul>
                    <ul>
                        <li><span class="fa fa-file chartwidth" id="84" onmouseover="visibleLink('84', 'Sales A/c', '1')" onmouseout="hideLink('84')" onclick="ViewLedgerMsg(84)"><span onclick="GetTreeViewChartOfAccountsByParam('84', 'Sales A/c')">Sales A/c </span><span class="closingbalance">INR 50.00Dr </span></span></li>
                    </ul>
                    <ul>
                        <li><span class="fa fa-folder-open chartwidth" id="98" onmouseover="visibleLink('98', 'Indirect Income', '1')" onmouseout="hideLink('98')"><span onclick="GetTreeViewChartOfAccountsByParam('98', 'Indirect Income')">Indirect Income </span><span class="closingbalance">INR 0.00Cr </span></span>
                            <ul>
                                <ul>
                                    <li><span class="fa fa-file chartwidth" id="99" onmouseover="visibleLink('99', 'Realized Exchange Gain', '2')" onmouseout="hideLink('99')" onclick="ViewLedgerMsg(99)"><span onclick="GetTreeViewChartOfAccountsByParam('99', 'Realized Exchange Gain')">Realized Exchange Gain </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                                </ul>
                                <ul>
                                    <li><span class="fa fa-file chartwidth" id="122" onmouseover="visibleLink('122', 'Rounding off Gain A/c', '2')" onmouseout="hideLink('122')" onclick="ViewLedgerMsg(122)"><span onclick="GetTreeViewChartOfAccountsByParam('122', 'Rounding off Gain A/c')">Rounding off Gain A/c </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                                </ul>
                                <ul>
                                    <li><span class="fa fa-file chartwidth" id="124" onmouseover="visibleLink('124', 'Discount Received A/c', '2')" onmouseout="hideLink('124')" onclick="ViewLedgerMsg(124)"><span onclick="GetTreeViewChartOfAccountsByParam('124', 'Discount Received A/c')">Discount Received A/c </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                                </ul>
                                <ul>
                                    <li><span class="fa fa-file chartwidth" id="140" onmouseover="visibleLink('140', 'Stock Income', '2')" onmouseout="hideLink('140')" onclick="ViewLedgerMsg(140)"><span onclick="GetTreeViewChartOfAccountsByParam('140', 'Stock Income')">Stock Income </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                                </ul>
                            </ul>
                        </li>
                    </ul>
                    <ul>
                        <li><span class="fa fa-file chartwidth" id="134" onmouseover="visibleLink('134', 'Clearing And Forwarding Rcd', '1')" onmouseout="hideLink('134')" onclick="ViewLedgerMsg(134)"><span onclick="GetTreeViewChartOfAccountsByParam('134', 'Clearing And Forwarding Rcd')">Clearing And Forwarding Rcd </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                    </ul>
                    <ul>
                        <li><span class="fa fa-file chartwidth" id="135" onmouseover="visibleLink('135', 'Transport charges received ', '1')" onmouseout="hideLink('135')" onclick="ViewLedgerMsg(135)"><span onclick="GetTreeViewChartOfAccountsByParam('135', 'Transport charges received ')">Transport charges received  </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                    </ul>
                    <ul>
                        <li><span class="fa fa-file chartwidth" id="156" onmouseover="visibleLink('156', 'Sales Discount A/c', '1')" onmouseout="hideLink('156')" onclick="ViewLedgerMsg(156)"><span onclick="GetTreeViewChartOfAccountsByParam('156', 'Sales Discount A/c')">Sales Discount A/c </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                    </ul>
                    <ul>
                        <li><span class="fa fa-file chartwidth" id="158" onmouseover="visibleLink('158', 'Stock Income A/c', '1')" onmouseout="hideLink('158')" onclick="ViewLedgerMsg(158)"><span onclick="GetTreeViewChartOfAccountsByParam('158', 'Stock Income A/c')">Stock Income A/c </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                    </ul>
                    <ul>
                        <li><span class="fa fa-file chartwidth" id="163" onmouseover="visibleLink('163', 'Exchange Gain A/c', '1')" onmouseout="hideLink('163')" onclick="ViewLedgerMsg(163)"><span onclick="GetTreeViewChartOfAccountsByParam('163', 'Exchange Gain A/c')">Exchange Gain A/c </span><span class="closingbalance">INR 0.00Cr </span></span></li>
                    </ul>
                </ul>
            </li>
            <li><span class="fa fa-arrow-down" style="width: 100%; color: red; font-weight: 700;"><span>Net Loss </span><span class="closingbalance">14,950.00Cr</span></span></li>
        </div>

现在我需要得到的内文

  • 为此我正在这样做:

    var items = [];
                var inputData = $('#divTreeViewIncomeDetails').find('li > span');
    
                for (var i = 0; i < inputData.length; i++) {
                    var position, data1, data2;
                    position = inputData[i].className;
                    data1 = inputData[i].children['0'].innerText.trim();
                    data2 = inputData[i].children['1'].innerText.trim();
                    var item = { position: position, data1: data1, data2: data2 }
                    items.push(item);
                }
    

    它在 IE、Chrome、Safari、Opera 中工作正常

    但不能在 FIREFOX 中!!!

    data1 = inputData[i].children['0'].innerText.trim();
    

    这一行我没有得到 FF 中的值,它跳过了代码

    是否有任何替代代码?

  • 最佳答案

    innerText 未在 FireFox 中实现 innerText 不是官方的。 您可能想使用 textContent 我相信它适用于所有浏览器

    编辑:(文档说它适用于 IE9 及更高版本)

    参见文档:link

    来自文档的小引述

    Differences from innerText

    Internet Explorer introduced element.innerText. The intention is pretty much the same with a couple of differences:

    Note that while textContent gets the content of all elements, including and elements, the mostly equivalent IE-specific property, innerText, does not. innerText is also aware of style and will not return the text of hidden elements, whereas textContent will. As innerText is aware of CSS styling, it will trigger a reflow, whereas textContent will not

    关于javascript - children.innerText 在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25915079/

    相关文章:

    javascript - 为什么 Onblur 不起作用(JQuery/Javascript)

    javascript - Chrome 和火狐浏览器 : pictures stick together

    Javascript 验证,其中字符串仅由任意数量的空格组成

    javascript - jquery - 更改文本颜色

    jquery - 从外部文件加载 jQuery 模板?

    javascript - 打开新窗口的书签将当前窗口转发到[对象窗口]?

    css - border-image-slice 在 Chrome 和 FireFox 中交换水平和垂直参数

    javascript - div 内的 div 没有出现?

    javascript - 是否可以将 Sass 变量传递给 Laravel/Blade/JS?

    javascript - Twitter Bootstrap 转到嵌套选项卡的特定选项卡