document.getelementById().innerText doesn't on firefox

document.getelementById().innerText doesn't on firefox

本文关键字:on firefox doesn getelementById innerText document      更新时间:2023-09-26

需要使用javascript获取 asp.net 标签文本,下面的javascript适用于IE和Chrome,但不适用于Firefox,如何使其适用于所有浏览器。

function showThumbnails_OnClick() {
        var id = document.getElementById('lblId').innerText;
        if (ChkBox.checked) {
            location.href = 'Result.aspx?Id=' + id;
        }
    }
<asp:Label ID="lblId" runat="server" Text="">

.innerText更改为.textContent

你必须编写一个处理这两种情况的函数:

function showThumbnails_OnClick() {
    var element = document.getElementById('lblId');
    var id = element.innerText || element.textContent;
    if (ChkBox.checked) {
        location.href = 'Result.aspx?Id=' + id;
    }
}

确保它可以在IE和FF上运行。

var c_id = document.getElementById("lblId");
var id = (c_id.textContent == undefined) ? c_id.innerText : c_id.textContent;