gpt4 book ai didi

javascript - 从 url 变量填充电子邮件字段

转载 作者:行者123 更新时间:2023-11-27 23:26:06 25 4
gpt4 key购买 nike

我尝试从 url 变量填充表单上的电子邮件字段,例如:https://my.site.org/site/SignupPage.html?email=jsavage980%40gmail.com它在大多数情况下都有效,只是它没有从电子邮件地址中提取“@”。这是我的代码:

<script type="text/javascript">
Y.use('jquery-noconflict', function() {

function getQuerystring(key, default_) {
if (default_ == null) default_ = "";
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
var qs = regex.exec(window.location.href);
if (qs == null)
return default_;
else
return qs[1];
}

var other_value = getQuerystring('email');
other_value = other_value.replace(/(%[a-zA-Z0-9].)/g, "");
other_value = other_value.replace(/(\+)/g, "");
jQuery('#primary_email').val(other_value);
});
</script>
not sure what I am missing here... been racking my brain all morning. Any help would be greatly appreciated! Thanks!

最佳答案

首先,您必须正确解码您的 URL:

var url = decodeURIComponent(this.location);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent

document.getElementById('output').textContent = decodeURIComponent(document.getElementById('input').textContent);
<div id="input">https://my.site.org/site/SignupPage.html?email=jsavage980%40gmail.com</div>
<div id="output"></div>

关于javascript - 从 url 变量填充电子邮件字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34950901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com