gpt4 book ai didi

javascript - 使用 javascript 填充输入值

转载 作者:行者123 更新时间:2023-12-03 12:02:30 24 4
gpt4 key购买 nike

我需要 JavaScript 解决方案。用户订阅后,我在成功页面中收到了来自 aweber 的数据。所以网址如下:

http://example.com/success/?email=example@email.com&name=Jhon&custom_phone=0005551114&custom_location=USA

他们提供了一些 JavaScript 解决方案来在网页或成功页面中显示数据...

引用:https://help.aweber.com/entries/21696333-How-Do-I-Display-Subscribers-Names-or-Email-Addresses-On-My-Thank-You-Page-

所以当我把

<script type="text/javascript">formData.display("name")</script>
<script type="text/javascript">formData.display("email")</script>
<script type="text/javascript">formData.display("custom_phone")</script>
<script type="text/javascript">formData.display("custom_location")</script>

值将显示在我的页面中。但是如何将值放入成功页面的输入字段中?

<form action="" method="post">
<input type="text" name="username" value="Jhon">
<input type="text" name="useremail" value="example@email.com">
<input type="text" name="phoneno" value="0005551114">
<input type="text" name="country" value="USA">
<input tyoe="submit" value="Submit">
</form>

请帮忙..

最佳答案

您可以稍微更改一下 Javascript 代码,如下所示:

<script type="text/javascript">
var formData = function() { var query_string = (location.search) ? ((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
var elements = [];
if(query_string) {
var pairs = query_string.split("&");
for(i in pairs) {
if (typeof pairs[i] == 'string') {
var tmp = pairs[i].split("=");
var queryKey = unescape(tmp[0]);
queryKey = (queryKey.charAt(0) == 'c') ? queryKey.replace(/\s/g, "_") : queryKey;
elements[queryKey] = unescape(tmp[1]);
}
}
}
return {
display: function(key) {
if(elements[key]) {
document.write('<input type="text" name="' + key + '" value ="' + elements[key] + '"');
}
else {
document.write("<!--If desired, replace everything between these quotes with a default in case there is no data in the query string.-->");
}
}
}
}
(); </script>

您的 HTML 将如下所示:

<form action="" method="post">
<script type="text/javascript">formData.display("name")</script>
<script type="text/javascript">formData.display("email")</script>
<script type="text/javascript">formData.display("custom_phone")</script>
<script type="text/javascript">formData.display("custom_location")</script>
<input tyoe="submit" value="Submit">
</form>

关于javascript - 使用 javascript 填充输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25351248/

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