innerHTML 中解决javascript问题

来源:互联网 发布:淘宝最美网红 编辑:程序博客网 时间:2024/05/22 14:42

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>最佳实践</title>
 <meta name="Generator" content="EditPlus">
 <meta name="Author" content="">
 <meta name="Keywords" content="">
 <meta name="Description" content="">
  <script language="javascript">
  function FindObj(n, d) {
   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
   if(!x && d.getElementById) x=d.getElementById(n); return x;
  }
  function pop_up(showText){
   var ShowText = FindObj("ShowText");
   JSValid.ShowWindow(showText, get_callback);
  }

  function get_callback(response){
   reInnerHTML(ShowText, response.value);            
  }
  
  var reInnerHTML = function(ele,innerHtml) {
   var nA=navigator.appVersion;
   if(nA.indexOf('MSIE')>=0)var curIE=nA.substr(nA.indexOf('MSIE')+5,3);
   if (curIE){
    innerHtml=innerHtml.replace(/<script([^>]*)>/gi,"<script$1 defer=/"true/">");
    var reStartScript=/^(/s*<script)/gi;
    if (reStartScript.test(innerHtml)){
     innerHtml="<span style=/"display:none;/">Hack IE</span>"+innerHtml;
     ele.innerHTML=innerHtml;
     ele.removeChild(ele.firstChild);
    }else{
     ele.innerHTML=innerHtml;
    }

   }else{
    var newObj=document.createElement(ele.tagName);
    newObj.id=ele.id;
    newObj.className=ele.className;
    newObj.innerHTML = innerHtml;
    ele.parentNode.replaceChild(newObj,ele);
   }
  }
 </script>
  </head>
  <body>
 
    <form id="Form1" method="post" runat="server">
    <div id="ShowText"></div>
    <input type="button" value="弹出" onclick="pop_up('人生')"/>
     </form>
 
 
  </body>
</html>

 


cs文件

 

public string ShowWindow(string showText)
  {
   return  "我的<script language=/"javascript/">alert('"+showText+"')</script>";
  }

原创粉丝点击