在这种情况下,我只想连接id
url 末尾的值。
无论如何,我刚刚找到了解决方案。
我想在 url 中添加值。
我现在的网址是
localhost:1000//settings/tab=contact-types
假设我有这个功能
function view(id){ #lets say the value of id is 1
localhost:1000//settings/tab=contact-types/1 #i want the current url look like this
}
我的表格的每一行都有按钮,当我点击它时,它将运行该view()
功能并显示模态以供查看。
我想在不重新加载/重新定位页面的情况下在 url 中添加我的参数的特定值。
我只是通过在我的函数上使用此代码找到了解决方案。
view: function(id)
{
var newurl = window.location.href +"/"+id
window.history.pushState({path:newurl},'',newurl);
}
该window.location.href
定义我当前的URL
我只是id
在当前 url 的末尾连接了 的值并使用了
window.history.pushState({path:newurl},'',newurl);
将其推送到网址中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句