0

网址: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 drop box onchange 事件中,最后都会像这样附加url。

我怎么能解决这个问题

4

1 回答 1

1

你需要专门编码你的网址..试试这个

function cat()
{
    var x = document.getElementById('cat').value;   
    url  = "http://localhost/back-office/index.php/staff/shopping/" + x;
    window.location = url;

}
于 2012-06-18T04:39:05.587 回答