Javascript 更改url并在更改公共标题中的下拉值时重新加载
我是yii新手,我想更改url,并在更改管理员公共标题字段中的下拉值时重新加载当前视图页面。 下拉列表是Javascript 更改url并在更改公共标题中的下拉值时重新加载,javascript,php,jquery,yii,yii-components,Javascript,Php,Jquery,Yii,Yii Components,我是yii新手,我想更改url,并在更改管理员公共标题字段中的下拉值时重新加载当前视图页面。 下拉列表是 echo$form->dropDownList($siteid,'selectedsiteid',$data,$htmlOptions,array('class'=>“表单控件”) 当前URL可能如下所示 1。http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/6 2.http://localhost/z
echo$form->dropDownList($siteid,'selectedsiteid',$data,$htmlOptions,array('class'=>“表单控件”)代码>
当前URL可能如下所示
1。http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/6
2.http://localhost/zyntegra_commoditylifev2/admin/category/viewCategory/sid/
3.http://localhost/zyntegra_commoditylifev2/admin/site/index
假设当前更改的下拉列表值为10
,如果当前url类似于(1)个,则我需要像这样更改url
http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/10
如果当前url类似于(2)一个然后
http://localhost/zyntegra_commoditylifev2/admin/category/viewCategory/sid/10
如果它与(3)一样,则无需重新加载
请有人帮我解决这个问题
提前谢谢试一下
var tagsUrl='http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/';
var catUrl='http://localhost/zyntegra_commoditylifev2/admin/category/viewCategory/sid/';
$(function(){
$('#your-select-id').on('change',function(){
href=window.location.href;
if(href.indexOf('viewTags') !== -1){
window.location.href=tagsUrl+this.value;//append value of select element
} else if(href.indexOf('viewCategory') !== -1){
window.location.href=catUrl+this.value;//append value of select element
}
});
});
// use location.href in url to get current url
var url='http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/110';
alert(url.split('sid/')[1]);//110
以上代码可能会帮助您完成任务
已更新,只获取sid,然后像这样尝试
var tagsUrl='http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/';
var catUrl='http://localhost/zyntegra_commoditylifev2/admin/category/viewCategory/sid/';
$(function(){
$('#your-select-id').on('change',function(){
href=window.location.href;
if(href.indexOf('viewTags') !== -1){
window.location.href=tagsUrl+this.value;//append value of select element
} else if(href.indexOf('viewCategory') !== -1){
window.location.href=catUrl+this.value;//append value of select element
}
});
});
// use location.href in url to get current url
var url='http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewTags/sid/110';
alert(url.split('sid/')[1]);//110
更新@salini回答如下:
function reloadpage() {
var sid = $( '#Site_selectedsiteid' ).val( );
var currentURL = window.location.pathname;
var n=currentURL.indexOf("/sid");// use '/sid' only in indexOf to remove else part
if(n!=-1) {
var newurl = currentURL.substring(0,n);
window.location.href = newurl + '/sid/' + sid;
}
}
是的,我已经解决了。这是我的iavascript代码
function reloadpage() {
var sid = $('#Site_selectedsiteid').val();
var currentURL = window.location.pathname;
var n = currentURL.indexOf("/sid/");
if (n != -1) {
var newurl = currentURL.substring(0, n);
window.location.href = newurl + '/sid/' + sid;
} else {
var n = currentURL.indexOf("/sid");
if (n != -1) {
var newurl = currentURL.substring(0, n);
window.location.href = newurl + '/sid/' + sid;
}
}
}
它工作正常。感谢@Roshan和@kumar为您提供的帮助您需要通过php提供帮助吗?或者javascript可以吗?javascript可以。我认为仅仅使用phpB是不行的,但是像这样的URL还有很多,我刚才只提到了其中的一些these@Salini你试过上面的解决方案吗?你面临的问题是什么?@kumar有更多类似的URL等ect@Salini但是,URL是相同的,但参数不同。对吗?如果url的最后一部分类似于/sid/或/sid/2(某些值),则需要将其更改为/sid/10(当前下拉值)。我在查看您的答案后再次更新了我的答案。请再试一次。