首页 > 解决方案 > 使用文本框中的参数调用 php

问题描述

我想制作一个有文本框的网站,如果用户输入“hello”并单击提交,我想显示 example.com/test.php?link=hello 我该怎么做?php 已经写好了我只需要用 html 或 php 做一些东西就可以显示 example.com/test.php?link=whatUserEnters

谢谢!

标签: phphtml

解决方案


    <!DOCTYPE html>
    <html>
    <body>

    <!--just create a text box, give an id to it.-->
    <input type="text" id="text_to_display" />

    <input type="button" value="Submit" onClick="concat();" />

    <!--Create a label or div assign a separate id to it too.-->
    <p id="concatenated_text"></p>

    <script>
        //Create a function in javascript.
        function concat() {
            //Get the value in function using that id.
            var text = document.getElementById("text_to_display").value;

            //Concatenate the value with the string and put it in div using id.
            var final_text = "example.com/test.php?link="+text;
            // you can use location.href to use it for link purpose
            location.href = final_text;
        }

    </script>

    </body>
    </html>

推荐阅读