【问题标题】:How to take input from user and show it on screen and when he shares the url the people who got the url can see that input如何从用户那里获取输入并将其显示在屏幕上,当他共享 url 时,获得 url 的人可以看到该输入
【发布时间】:2021-01-27 08:28:36
【问题描述】:
<h1>Lalan</h1>
<input type="text" name="text" id="text" maxlength="12"> <label for="text"> Type your name here</label> <br><input type="submit" value="Submit"> </form>

我有一个问题,我如何将它保存在 url 中,就像在许多 url 中一样,名称被保存,并且只有他们可以看到它

【问题讨论】:

    标签: javascript html input inputstream


    【解决方案1】:

    您需要以某种方式持久化数据。有很多方法可以解决这个问题。您可以使用 Redis 之类的缓存,也可以在数据库中实现记录。我认为最简单的方法是将数据保存在您要共享的查询字符串中。关于如何在这里实现这一点有一个非常好的答案: [从代码中添加或更新您的查询字符串][1] [1]:https://stackoverflow.com/questions/5999118/how-can-i-add-or-update-a-query-string-parameter

    在查询中设置好数据后,您可以查看查询中是否有任何信息,如果有,您可以将其呈现为输入的默认值。为此,您可以使用:

    const urlParams = new URLSearchParams(window.location.search);

    const pastUserInput = urlParams.get(`pastUserInput`)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 2018-06-19
      • 2018-04-19
      • 1970-01-01
      相关资源
      最近更新 更多