【问题标题】:Generate link with two input fields使用两个输入字段生成链接
【发布时间】:2014-05-17 08:56:15
【问题描述】:

我有两个输入字段

字段 1 和字段 2

我想在点击提交按钮时生成一个外部链接

例如链接如下,

www.mystie.com/field1 + sometext + field2


我需要这个公式与谷歌地图方向一起使用

【问题讨论】:

    标签: java javascript html textfield


    【解决方案1】:

    用户 request.getParameter( "field1" ) 在您的操作 servlet 中

    String link = request.getParameter( "field1" ) +"sometext" + request.getParameter( "field2" );
    

    你的 html 在哪里

    <form action="myServlet" method="post">
      <input name="field1"/>
      <input name="field2"/>
    </form>
    

    【讨论】:

      【解决方案2】:
      String link = String.format("www.mysite.com/%s/sometext/%s",field1.getText(),field2.getText());
      

      【讨论】:

      • 这是javascript吗? ?%s,还是特殊库??因为这是我第一次看到它
      • 它是 Java。这个问题不清楚链接将在哪里形成。
      【解决方案3】:

      您可以使用 Javascript 来执行此操作。

      试试这个

      function submitclick(){
      var text1=  document.getElementByID("feild1").value;
      var text2=  document.getElementByID("feild2").value;
      document.getElementByID("submitbuttonATag").href=text1+sometext+text2;
      
      // Finally when the link is modified generate click
      document.getElementByID("yourA_tag").click();
      }
      

      【讨论】:

        【解决方案4】:

        使用 jquery

        ("#submitButton").click(function(){
        var url="www.mysite.com/";
        url= url + $("#feild1").val();
        url = url + "sometext";
        url = url +  $("#feild2").val();
        //Then use your url
         });
        

        【讨论】:

          猜你喜欢
          • 2015-02-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多