js怎样获取火狐a标签里面的内容呢?<a>获取这几个字</a>

其他浏览器都支持innerText,火狐的不支持,有什么函数代替啊
我已经晓得了,用innerHTML,不用了回答了

第1个回答  2014-12-02
  您好!很高兴为您答疑。
  如果想要在火狐下使用该方法,可以尝试重写一下。实例代码请参考:
  <script language=”javascript”>
function isIE(){ //ie?
if (window.navigator.userAgent.toLowerCase().indexOf(“msie”)>=1)
return true;
else
return false;
}
if(!isIE()){ //firefox innerText define
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;
}
);
}
</script>
  如果对我们的回答存在任何疑问,欢迎继续问询。追问

没必要这么复杂,target.innerText || target.innerHTML;,这句话已经可以了,已经知道了,不用回答了

第2个回答  2014-12-02
.text()直接用这个试试!追问

text只有IE可用

相似回答