<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function showRightContent(obj) {
alert(obj);
alert(obj.innerText);
}
</script>
</head>
<body>
<a href="#" onclick="showRightContent(this)">新闻</a>
</body>
</html>在IE和谷歌下面两个弹出信息都是一样的,http://loaclhost:1803/a.htm# 、新闻
但是在火狐下面弹出的是http://loaclhost:1803/a.htm# 和 undefined怎样在火狐下面也可以拿到<a>中的文字“新闻”两个字
alert(obj);
alert(obj.innerHTML);
}
你可以用jquery的text 来解决跨浏览器的兼容问题<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function showRightContent(obj) {
//alert(obj);
//alert(obj.innerText);
alert($("#ll").text());
}
</script>
</head>
<body>
<a id="ll" href="#" onclick="showRightContent(this)">新闻</a>
</body>
</html>
因为firefox下面貌似没有innerText这个属性的如果要兼容的话,jquery是个不错的选择的