发布于 2017-01-06 12:33:24 | 104 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Javascript教程,程序狗速度看过来!

JavaScript客户端脚本语言

Javascript 是一种由Netscape的LiveScript发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为客户提供更流畅的浏览效果。


在测试时发现firefox不支持innerText,该怎么办呢?其实很简单,本文为大家提供了一个解决方法,感兴趣的朋友可以参考下,希望对大家有所帮助
js代码:
 
<script> 
window.onload = function(){ 
<PRE class=javascript name="code">if(window.navigator.userAgent.toLowerCase().indexOf("msie")==0){ //firefox innerText 
HTMLElement.prototype.__defineGetter__( "innerText", 
function(){ 
var anyString = ""; 
var childS = this.childNodes; 
for(var i=0; i<childS.length; i++) { 
if(childS[i].nodeType==1) 
anyString += childS[i].tagName=="BR" ? '\n' : childS[i].textContent; 
else if(childS[i].nodeType==3) 
anyString += childS[i].nodeValue; 
} 
return anyString; 
} 
); 
HTMLElement.prototype.__defineSetter__( "innerText", 
function(sText){ 
this.textContent=sText; 
} 
); 
};</PRE>var test = document.getElementById("test");<BR> 
var innerText_s = test.innerText;<BR> 
if( innerText_s == undefined ){<BR> 
alert( test.textContent ); // firefox<BR> 
}else{ <BR> 
alert( test.innerText);<BR> 
};<BR> 
<BR> 
<BR> 
}<BR> 
<BR> 
<BR> 
</script><BR> 
<PRE></PRE> 
<P><BR> 
</P> 
<P>html代码</P> 
<P><div id="test"><BR> 
      <span style="color:red">test1</span> test2<BR> 
</div><BR> 
</P> 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务