问题
This is my JavaScript code:
function selectRow(objTR) {
for (i = 0; i < ddlModalityList.options.length; i++) {
if (ddlModalityList.options[i].text == objTR.cells[1].innerText.trim()) break;
}
ddlModalityList.options[i].selected = true;
txtSSAETitle.value = objTR.cells[2].innerText.trim();
txtSSName.value = objTR.cells[3].innerText.trim();
}
This is repeater code. On row click I am passing id of tr and displaying respective td value in respective dropdownlist and textboxes. This code works fine in IE but fails in Mozilla Firefox.
<tr onclick="selectRow(this);">
<td class="csstablelisttd" style="display: none;" >
<%#Eval("Acq_Modality_ID")%>
</td>
<td class="csstablelisttd" >
<asp:Label ID="lblModality" runat="server" Text='<%#Eval("Modality")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblSchdledStAETitle" runat="server" Text='<%#Eval("Scheduled_Station_AE_Title")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblSchdleStationAEName" runat="server" Text='<%#Eval("SCHEDULED_STATION_NAME")%>'></asp:Label>
</td>
</tr>
回答1:
Firefox does not support innerText. You can use textContent instead. However, older IE does not support textContent, so you'll need to use one and fall back to the other.
function getInnerText(el) {
return el.textContent || el.innerText;
}
Note that they're not identical, but for your purposes it will be fine.
回答2:
Use innerHTML instead of innerText. InnerText will not work in FF. innerHTML will work on both of them.
http://forums.asp.net/p/1228392/2210082.aspx
回答3:
Firefox does not support innerText.. you should use jquery so that you dont need to care about the difference in browers implementation
so using jquery your code would be
function selectRow(objTR) {
for (i = 0; i < ddlModalityList.options.length; i++) {
if (ddlModalityList.options[i].text == $(objTR).children('td').eq(1).html().trim()) break;
}
ddlModalityList.options[i].selected = true;
txtSSAETitle.value = $(objTR).children('td label').eq(2).html().trim();
txtSSName.value = $(objTR).children('td label').eq(3).html().trim();
}
im leaving the ddlModalityList as it is because i dont know what it is.
回答4:
function selectRow(objTR) {
for (i = 0; i < ddlModalityList.options.length; i++) {
if (ddlModalityList.options[i].text == $(objTR).children('td').eq(1).html().trim()) break;
}
ddlModalityList.options[i].selected = true;
txtSSAETitle.value = $(objTR).children('td label').eq(2).html().trim();
txtSSName.value = $(objTR).children('td label').eq(3).html().trim();
}
回答5:
document.getElementById('InputText').innerHTML.replace(/<.+?>/gim,''));
来源:https://stackoverflow.com/questions/10428965/mozilla-firefox-not-getting-value-innertext