url : http://localhost/back-office/index.php/staff/shopping
当我更改每个onchange事件的类别时,我希望URL应该是这样的
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工作,但URL被附加像
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 投递箱更改事件中,URL 都会像这样附加到末尾。
我该如何解决这个问题
你需要专门编码你的网址。试试这个
function cat()
{
var x = document.getElementById('cat').value;
url = "http://localhost/back-office/index.php/staff/shopping/" + x;
window.location = url;
}