日期:2014-05-16 浏览次数:20355 次
<a id="contact" class="btn btn-default" role="button" data-toggle="dropdown" data-target="#">移动电话<span class="caret"></span></a>
var $a = document.getElementById("contact");
////////////
$a.firstChild.nodeValue = 'TTTT';
$a.firstChild.textContent = 'TTTT';
$a.firstChild.data= 'TTTT';
///////////////
$a.childNodes[0].nodeValue = 'TTTT';
////////////
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<a id="contact" class="btn btn-default" role="button" data-toggle="dropdown" data-target="#">移动电话<span class="caret"></span></a>
<script>
var contact = document.getElementById('contact').innerHTML;
var contactText = contact.replace(/<[^>].*?>/g,"");
contact = contact.replace(contactText,'常用邮箱');
document.getElementById('contact').innerHTML = contact;
</script>
</body>
</html>
document.getElementById('contact').childNodes[0].nodeValue = '常用邮箱';