【问题标题】:Add user input on Action URL在操作 URL 上添加用户输入
【发布时间】:2021-11-28 15:00:44
【问题描述】:

当用户点击提交时,它应该打开http://127.0.0.1:5000/default/+UserInput。但是 giveme() 函数返回“?keyword=UserInput”而不是“UserInput”。如何获得正确的网址?

    <form id="myform" class="form-horizontal"  action="http://127.0.0.1:5000/default/" + 
            giveme() method="get" >

        <div id="searchkeyword">
             <div class="form-group">
                <label for="keyword" class="col-sm-3 control-label">Enter keyword</label>
                <div class="col-sm-4">
                    <input type="text" name="keyword" id="keyword" class="form-control">
                    <br>
                </div>
            </div>
        </div>


        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" class="btn btn-primary">Submit &raquo;</button>
                <span class="small-paddingleft">*Required</span>
            </div>
        </div>
    </form>
   <script>
   function giveme(){
        document.getElementById("keyword").value;
   }
   </script>

【问题讨论】:

    标签: javascript python html flask url


    【解决方案1】:

    这是一个得到你想要的函数:

    function giveme() {
      const params = new URLSearchParams(window.location.search);
      document.getElementById("keyword").value = params.get('keyword');
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-15
      • 2020-03-31
      • 2018-06-15
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多