特殊字符替换为空格
Special character replace with space
我正在传递变量 true url 和空格会自动替换为浏览器的"+"或"%20"。重定向页面后,我想正确拆分这个词。
例如:-http://localhost:8008/Login.aspx?stid=Are 你快乐
加载登录页面后,这会自动转换,
http://localhost:8008/Login.aspx?stid=Are+You+Happy
或
http://localhost:8008/Login.aspx?stid=Are%20You%20Happy
加载页面后如何获取此 stid 变量,
你快乐吗
有没有办法使用 javascript 或 jquery 来做到这一点?
当我发送参数时,我想要相同的结果,
http://localhost:8008/Login.aspx?stid=Are+You+Happy
我想要的结果也应该像下面一样。
是+你+快乐
这两个功能都可以由javascript或jquery完成吗?
//decode function
function decode(encodedStr) {
return decodeURIComponent(encodedStr.replace(/'+/g, " "));
}
//encode function
function encode(unencoded ) {
return encodeURIComponent(unencoded).replace(/'/g,"%27").replace(/"/g,"%22");
}
你也可以使用 JQuery.params((:
var myObject = {
stid: 'You are happy',
b: [ 1, 2, 3 ],
.......
};
var recursiveEncoded = $.param( myObject );
var recursiveDecoded = decodeURIComponent( $.param( myObject ) );
alert( recursiveEncoded );
alert( recursiveDecoded );
这应该可以解决问题
var url = "http://localhost:8008/Login.aspx?stid=Are%20You%20Happy",
decoded_url = decodeURIComponent(url.replace(/'+/g, " "));
alert(decoded_url.split('stid=')[1]);
相关文章:
- 用空格替换下划线PHP
- 用空格替换+
- 用空格替换单引号和其他符号
- 如何用空格替换下划线
- 用空格替换regex字符
- JavaScript 替换是将每个空格替换为非空格
- 不能使用正则表达式将空格替换为零宽度空间
- 将 url 中的空格替换为代码
- 在 Netbeans 代码模板中将空格替换为下划线
- 将空格替换为
- 将空格和空格替换为逗号,并在 JS 中使用连字符
- 为什么 标记将空格替换为 %2520?如何解决问题
- 将换行符+4空格替换为
- 如何在javascript中用一个特殊字符开头的单词内的空格替换下划线
- 如何在javascript中用空格替换换行符
- 将空格替换为
- 如何在scala代码中用单个空格替换所有连续的下划线
- 将搜索输入框中的所有空格替换为&性格
- 用javascript将空格替换为逗号
- 将整个字符串中的空格替换为unedrscores