url:http://localhost/back-office/index.php/staff/shopping
当我在每个onchange事件上更改类别时,我希望网址应该像这样
http://localhost/back-office/index.php/staff/shopping/1
http://localhost/back-office/index.php/staff/shopping/2
因为我在变更事件上写了javascript
function cat()
{
var x = document.getElementById('cat').value;
document.location = "shopping/" + x;
}
<select name="cate" id="cat" onchange="cat()">
<option value="0">Select Cateogry</option>
<?php
foreach($get_cat as $category)
{
echo "<option value=$category->categoryid>$category->category</option>";
}
?>
</select>
javscript有效,但是网址会像
一样被追加http://localhost/back-office/index.php/staff/shopping/shopping/2
http://localhost/back-office/index.php/staff/shopping/shopping/shopping/shopping/shopping/shopping/1
在每个cagetory drop box onchange事件上,url会在最后添加这样的内容。
我怎么能解决这个问题
答案 0 :(得分:1)
你需要专门编码你的网址..这个
function cat()
{
var x = document.getElementById('cat').value;
url = "http://localhost/back-office/index.php/staff/shopping/" + x;
window.location = url;
}