从HTML传递URL中的参数

时间:2018-03-05 22:23:09

标签: html http

首先,请允许我原谅在网络开发中成为这样一个菜鸟。我到处寻找如何做到这一点,找不到具体告诉我的任何事情。

这是我的链接:

<td><a style="color:red;text-align:left" href=/sponsor/manageuser.htm?user=" 
+ target=_self"</a></td>

我需要参数&#34; user&#34;要附加,我还需要与用户完全相同的链接值。像这样:

<td><a style="color:red;text-align:left" 
href=/sponsor/manageuser.htm?user="12345" 12345</a></td>

问题是我必须将参数和链接放在标记内。至少我认为这是问题所以你点击12345链接,它会将12345附加到URL并将其作为GET方法传递。我的表格是GET:

<form class="frm" method="get" name="currentusers" id="currentusers" 
action="currentusers.htm">

接下来我的网址看起来像是什么,当然我收到了404错误:

http://localhost:8080/sponsor/manageuser.htm?user=target=

任何建议都需要提前感谢。

1 个答案:

答案 0 :(得分:0)

jQuery方式:

您可以做的是让每个链接调用一个函数,并将链接的值传递给函数。然后函数append()将添加一个隐藏的输入值以及您单击的数字。最后,该函数将表单提交到manageuser.htm页面,其中包含&#34;?user = 1234&#34;按照你的要求。

您可以通过复制和粘贴此代码并在计算机上打开代码来查看代码的工作原理。

<!DOCTYPE html>

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>

<body>

    <form id = "form1" method="get" action="sponsor/manageuser.htm"> 

        <table>

            <tr>

                <td><button id="1543" onclick="append(1543)">1543</button></td>

                <td><button id="3515" onclick="append(3515)">3515</button></td>

                <td><button id="1115" onclick="append(1115)">1115</button></td>

            </tr>

        </table>

    </form>

<script>

    function append(user_number)
    {   

        $('<input />').attr('type', 'hidden').attr('name', "user").attr('value', user_number).appendTo('#form1');

        $('#form1').submit();

     }

</script>

</body>

</html>
相关问题