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

麻烦看下这段代码。为什么在firefox里点击超链接不跳转,而在IE中就跳转了。本人意愿是不跳转
HTML code
html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>image gallery</title>
    <link rel="Stylesheet" href="styles/layout.css" type="text/css"/>
    <script type="text/javascript">
        function showPic(whichpic)
        {
            imgSource = whichpic.getAttribute("href");
            placeholder = document.getElementById("placeholder");
            placeholder.setAttribute("src",imgSource);
            
            var text = whichpic.getAttribute("title");
            var description = document.getElementById("description");
            description.firstChild.nodeValue = text;
            //alert(description.childNodes[0].nodeValue);
        }
        function countBodyChildren()
        {
            var body_element = document.getElementsByTagName("body")[0];
            nodeLength = body_element.childNodes.length;
            alert(body_element.nodeType);
//            for(i=0;i<nodeLength;i++)
//            {
//                alert(body_element.childNodes[i].nodeType);
//            }
        }
        //window.onload = countBodyChildren;
    </script>
</head>
<body>
    <h1>Snapshots</h1>
    <ul>
        <li>
            <a href="img/1.jpg" title="A fireworks display" onclick="return false;showPic(this);">Fireworks</a>
        </li>
        <li>
            <a href="img/2.jpg" title="A cup of black coffee" onclick="showPic(this);return false;">Coffee</a>
        </li>
        <li>
            <a href="img/3.jpg" title="A red,red rose" onclick="showPic(this);return false;">Rose</a>
        </li>
        <li>
            <a href="img/4.jpg" title="The famous clock" onclick="showPic(this);return false;">Big Ben</a>
        </li>
    </ul><br /><br />
    <img id="placeholder" src="img/1.jpg" alt="my image gallery" width="400px" height="300px" />
    <p id="description">Choose an image.</p>
    
</body>
</html>



------解决方案--------------------
有些关键字不要使用为好,参见
http://blog.csdn.net/net_lover/article/details/7162136
------解决方案--------------------
var placeholder = document.getElementById("placeholder");//加个var就可以了