如何在没有表单的情况下将查询数据发布到URL?

时间:2012-04-05 14:54:39

标签: javascript html

我需要通过点击链接传递一些信息,而不是使用带有表单和输入按钮的action =“GET”。这可能吗?这只是客户端,没有服务器,所以关于PHP等的建议在这种情况下没有用。

4 个答案:

答案 0 :(得分:5)

在你的锚中,更改href以在末尾包含查询字符串。

e.g。

 <a href="http://www.example.com/test.html?parameter=2">

答案 1 :(得分:4)

假设您可以访问客户端上的变量,您可以执行以下操作:

<script type="text/javascript">
    navigateToPage = function(val){        
        window.location.href = "/somefolder/somefile.htm?id=" + val;
    }
</script>
<input type="button" value="Navigate" onclick="navigateToPage(5);" />

答案 2 :(得分:2)

您需要使用JavaScript来获取所有值,然后将它们合并到一个URL中。

以下是一个示例(使用jQuery库):

<a href="http://example.com/test.html" id="paramLink">Click</a>

<script>
$(function(){
  // The data, from the page
  var id = 1, name = 'test';

  // Add event to link
  $('#paramLink').click(function(e){
    e.preventDefault(); // Stop the browser from following the link

    location.href = $(this).attr('href')+'?id='+id+'&name='+name; // Build the URL
  });
});
</script>

答案 3 :(得分:0)

将您的信息放入锚点并随之发布

<a href="yourpage.php?id=2&action=edit"> click! </a>

如何在重定向页面上获取这些值;如果你使用PHP。

$id=intval($_REQUEST['id']);
$action=$_REQUEST['action'];
相关问题