我有这个jquery脚本(感谢之前的成员在这里)从url中获取电子邮件或任何其他查询字符串并填充页面上相应输入字段的值…
所以…表单输入类似于:
<input type="text" name="email" >
脚本是…
$(function () {
//grabs the entire query string
var query = document.location.search.replace('?', '');
//extracts each field/value pair
query = query.split('&');
//runs through each pair
for (var i = 0; i < query.length; i++) {
//splits up the field/value pair into an array
var field = query[i].split("=");
//targets the field and assign its value
$("input[name='" + field[0] + "'], select[name='" + field[0] + "']").val(field[1]);
}
问题:url的编码如下:
http://www.example.com/?email=some%40email.com
所以在我的代码中,我怎么能解码'%40'回到'@' 之前它填充输入字段中的值?指导吗?
可以使用纯javascript
decodeURIComponent('some%40email.com')
decodeuriccomponent ('@')
decodeURIComponent (40 ' % ')