用于Internet Explorer的javaScript中的innerHTML

时间:2022-11-17 11:11:35

I have used innerHtml in my java based web application. JavaScript works fine with Mozilla Firefox but it is not working in InternetExplorer.

我在基于java的Web应用程序中使用了innerHtml。 JavaScript可以与Mozilla Firefox一起使用,但它在InternetExplorer中不起作用。

Could you please tell me how to make it work in Internet Explorer too. or what is substitute of innerHTML in IE.

你能告诉我如何让它在Internet Explorer中运行吗?或什么是IE中innerHTML的替代品。

Code is:

function show() {    
  if('number' == typeof this.rowIndex) {
    var rn = this.rowIndex;
    var cell = tableRows[rn].cells;
    employeeCode = cell[0].innerHTML;
    //..........
  }
}

Thank and regards

谢谢,问候

4 个解决方案

#1


7  

Using jQuery eliminates problems like this in nearly all cases. It handles the minor differences between major browsers so you can do simple things like:

在几乎所有情况下,使用jQuery都可以消除这样的问题。它处理主要浏览器之间的细微差别,因此您可以执行以下简单操作:

$("div.summary").html(); /* Gets HTML from <div class="summary"> */
$("div.summary").html("Hello"); /* Sets the HTML */

#2


1  

innerHTML, to be cross-browser, needs something like this :

innerHTML,跨浏览器,需要这样的东西:

<script type="text/javascript">

function show (where,what) {
   var ie = document.all;  // Internet Explorer
   var ns = document.getElementById && !document.all;  // Firefox, Netscape, other browsers
   if(ie) { 
      eval("document.all."+where).innerHTML = what; }
   else if(ns) {
      document.getElementById(where).innerHTML = what; }
}

</script>

<a href="javascript:show('display','Hallo')">try</a>
<div id="display"></div>

As I found in http://usenet.manifestinteractive.com/manifestElementControl.html?/usenet/manifestElementControl.html

正如我在http://usenet.manifestinteractive.com/manifestElementControl.html?/usenet/manifestElementControl.html中找到的那样

#3


1  

Try innerText in place of innerHTML.

尝试使用innerText代替innerHTML。

#4


0  

You first need to check if the browser is using internet explorer then get the version. after you have the browsers version you can use an if statement to tell it to use InnerText for IE and InnerHTML for the rest of the browsers.

首先需要检查浏览器是否使用Internet Explorer,然后获取版本。拥有浏览器版本后,您可以使用if语句告诉它使用InnerText for IE和InnerHTML用于其他浏览器。

InnerText is the alternate way of InnerHTML for Internet Explorer. Hope this helps.

InnerText是Internet Explorer的InnerHTML的替代方式。希望这可以帮助。

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
}

 //detect if IE version is greater than 1 then deletes row content
if (ieversion>=1) {
row.innerText = '';
} else {
row.innerHTML = '';
 }

#1


7  

Using jQuery eliminates problems like this in nearly all cases. It handles the minor differences between major browsers so you can do simple things like:

在几乎所有情况下,使用jQuery都可以消除这样的问题。它处理主要浏览器之间的细微差别,因此您可以执行以下简单操作:

$("div.summary").html(); /* Gets HTML from <div class="summary"> */
$("div.summary").html("Hello"); /* Sets the HTML */

#2


1  

innerHTML, to be cross-browser, needs something like this :

innerHTML,跨浏览器,需要这样的东西:

<script type="text/javascript">

function show (where,what) {
   var ie = document.all;  // Internet Explorer
   var ns = document.getElementById && !document.all;  // Firefox, Netscape, other browsers
   if(ie) { 
      eval("document.all."+where).innerHTML = what; }
   else if(ns) {
      document.getElementById(where).innerHTML = what; }
}

</script>

<a href="javascript:show('display','Hallo')">try</a>
<div id="display"></div>

As I found in http://usenet.manifestinteractive.com/manifestElementControl.html?/usenet/manifestElementControl.html

正如我在http://usenet.manifestinteractive.com/manifestElementControl.html?/usenet/manifestElementControl.html中找到的那样

#3


1  

Try innerText in place of innerHTML.

尝试使用innerText代替innerHTML。

#4


0  

You first need to check if the browser is using internet explorer then get the version. after you have the browsers version you can use an if statement to tell it to use InnerText for IE and InnerHTML for the rest of the browsers.

首先需要检查浏览器是否使用Internet Explorer,然后获取版本。拥有浏览器版本后,您可以使用if语句告诉它使用InnerText for IE和InnerHTML用于其他浏览器。

InnerText is the alternate way of InnerHTML for Internet Explorer. Hope this helps.

InnerText是Internet Explorer的InnerHTML的替代方式。希望这可以帮助。

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
}

 //detect if IE version is greater than 1 then deletes row content
if (ieversion>=1) {
row.innerText = '';
} else {
row.innerHTML = '';
 }