传参数: 不让中文乱码 encodeURI()这个方法
window.open("detail?name1=" + encodeURI(filename) + "&name2=" + encodeURI(functionname))
获取参数:
var afterUrl = window.location.search.substring(1); //这是获取url后面的值
console.log(decodeURIComponent(afterUrl)) //这是中文转码 不乱码
接下来获取参数,就可以靠字符串截取,分割等方法获取了。
str.split('&') 如果你的参数含有& 这个 ,就不能用这个方法了
参考方法:substring(from,to)
本文介绍如何使用encodeURI()和decodeURIComponent()方法处理URL中的中文参数,避免乱码问题。通过具体示例,展示了如何在设置和获取URL参数时正确编码和解码中文字符,确保网页间的参数传递准确无误。

被折叠的 条评论
为什么被折叠?



