的index.html
<a href="product.html#category1">category 1</a>
<a href="product.html#category2">category 2</a>
<a href="product.html#category3">category 3</a>
product.html
$(document).ready(function(){
var item = toLowerCase((document.location.hash)).replace('#','');
if(/category[1-3]/i.test(item)){
changeIframe(item);
}else{
changeIframe(defaultitem);
}
});
如果你正在使用PHP
的index.html
<a href="product.html?item=category1">category 1</a>
<a href="product.html?item=category2">category 2</a>
<a href="product.html?item=category3">category 3</a>
產品。作爲查詢字符串HTML
<script>
<?php
if(isset($_GET['item']) && preg_match("/category[1-3]/", $_GET['item'])){
echo "changeIframe(" . $_GET['item'] .");";
}else{
echo "changeIframe(defaultitem);";
}
</script>
我想你會需要使用PHP或其他一些編程語言,否則你可能有爆炸的網址在js – Class 2013-04-10 04:54:50