重複的可能呢?
<h1 id="header">home</h1>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#product">Product</a></li>
<li><a href="#about">About</a></li>
</ul>
<script type="text/javascript">
window.onload = function(e) {
var links = document.getElementsByTagName('a');
for (var i=0; i < links.length; i++) {
links[i].addEventListener('click', function(e) {
var hash = this.href.split('#')[1];
if(hash.length) {
if(hash == 'product') {
alert('Sorry, page in development');
e.preventDefault();
}else{
document.getElementById('header').innerHTML = hash;
}
}
}, false);
};
};
// OR
window.onhashchange = function(e) {
var hash = window.location.hash.substr(1);
if(hash.length) {
if(hash == 'product') {
alert('Sorry, page in development');
window.history.back();
}else{
document.getElementById('header').innerHTML = hash;
}
}
};
</script>
改變了方法?由用戶? – 2011-01-11 01:43:13