日期:2014-05-16  浏览次数:20448 次

在HTML页里调用JS文件修改P标签里的内容,在线等。
页面代码
HTML code
<div class="copyright"> 
    <ul>
    <li><a href="ContactUs.htm" class="white">联系我们</a> <span>|</span></li>
    <li><a href="about.htm" class="white">关于我们</a> <span>|</span></li>
    <li><a href="Joinus.htm" class="white">加入我们</a> <span>|</span></li>
    <li><a href="ContactUs.htm" class="white">联系我们</a></li>
    </ul>
    <p class="white">替换掉这里</p>
</div>


我要在JS文件里面写个方法替换掉HTML页里的P标签里的文字,求解决方案。

------解决方案--------------------
<p class="white" id='r'>替换掉这里</p>
<script>
function replace(value)
{
document.getElementById('r').innerHTML = value
}
replace('替换后的内容')
</script>
------解决方案--------------------
HTML code


<script type="text/javascript">
    document.getElementsByTagName('p').item(0).innerHTML = '你好';
</script>

------解决方案--------------------
HTML code
<!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>
    <script>
        function change() {
            var a = document.getElementById("white");
            a.innerHTML = '你想替换成什么啊?!';
        }
    </script>
</head>
<body>
<div class="copyright"> 
    <ul>
    <li><a href="ContactUs.htm" class="white">联系我们</a> <span>|</span></li>
    <li><a href="about.htm" class="white">关于我们</a> <span>|</span></li>
    <li><a href="Joinus.htm" class="white">加入我们</a> <span>|</span></li>
    <li><a href="ContactUs.htm" class="white">联系我们</a></li>
    </ul>
    <p id="white">替换掉这里</p>
</div>
<input type='button' value='change' id='aa' onclick="change()"/>
</body>
</html>