这是我的第一篇文章,我希望能帮助您理解我的问题。我是这种编程语言的新手!所以...
我有这个选择菜单,这是代码
select name="select3" id="select3" value="" onChange="
var x=this.options[this.selectedIndex].value;
var k=document.form3.chk_list_hidden.value;
if(this.selectedIndex!=0){
k=x;
document.location.replace(window.location.href='<? $uri=$_SERVER['REQUEST_URI']; echo $uri.'&selected=';?>'+k); }"
它有效!但结果是 http://localhost/test.php?array[1]&array[2]&array[3]&selected=array[1]
如果我从选择菜单中选择另一个值,结果是http://localhost/test.php?array[1]&array[2]&array[3]&selected=array[1]&selected=array[2]
但我想将 &selected=array[1] 替换为 &selected=array[2]
我尝试任何东西并搜索它,但我找不到任何东西......:(
最佳答案
在最后一行尝试这个
document.location.replace(window.location.href='<? if(strstr($_SERVER['REQUEST_URI'], '&selected', true)) { $uri=strstr($_SERVER['REQUEST_URI'], '&selected', true);} else { $uri=$_SERVER['REQUEST_URI']}; echo $uri.'&selected=';?>'+k); }"
关于php - javascript+php 更改 url 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4680625/