Firefox不喜欢jquery中的.val?

时间:2012-06-08 20:09:58

标签: javascript jquery internet-explorer firefox

在IE浏览器中工作,在Firefox中,两个字段为空白,并且在分配后,名称在EditUserRoles中未定义:

从gridview调用GetRows,调用editUserRoles

<asp:TemplateField HeaderText="Action">
                    <ItemTemplate>                       
                        <input type="button" id="btnEditUserRoles" style="width:60px;"  onclick="GetRows(this.parentNode.parentNode.rowIndex)" value="Edit" />
                    </ItemTemplate>
                </asp:TemplateField>

<input type="text" disabled="disabled" id="txtAkoUserName" />
<input type="text" id="txtUserName" />

function GetRows(index) {
        var userGrid = document.getElementById('<%=gridUserRoles.ClientID%>');
        EditUserRoles(index, userGrid);
    }
function EditUserRoles(rowIndex, userGrid) {
    if (null != userGrid) {
        var userName = userGrid.rows[rowIndex].cells[0].innerText;
        var name = userGrid.rows[rowIndex].cells[1].innerText;
        LoadEditForm(userName, name);
}

function LoadEditForm(userName, name) {
    $("#txtAkoUserName").val(userName);
    $("#txtUserName").val(name);
}

1 个答案:

答案 0 :(得分:6)

Firefox does not support innerText。只需使用jQuery来避免这些跨浏览器问题(这就是它的用途):

var userName = $(userGrid.rows[rowIndex].cells[0]).text();
var name = $(userGrid.rows[rowIndex].cells[1]).text();