简体   繁体   English

如何给href赋值,就像对提交所做的那样?

[英]How do I give a value to an href as its done to a submit?

I named a submit and an href and when I test the conditions submit works but the href does not and there is no error displayed . 我命名了一个提交和一个href,当我测试条件提交时可以工作,但是href却没有,并且没有显示错误。 Please any help will be appreciated Bellow is the code 请任何帮助将不胜感激贝娄是代码

<form action="test.php" method="post"/>
<a href="#" name="amhref" >Href</a>
<input type ="submit" name="button"  value="button">
</form>
<?php
if(isset($_POST['amhref'])){
echo ("<h1>I am href </h1>");
}else if(isset($_POST['button'])){
echo ("<h1>I am the button</h1>");
}
?>

a link <a> is not sent with a form. 链接<a>不随表格一起发送。 so any data you would like to pass should be done through the href field. 因此,您要传递的所有数据都应通过href字段完成。 this is done with a get method, so please note the $_GET 这是通过get方法完成的,因此请注意$ _GET

<form action="test.php" method="post"/>
<input type ="submit" name="button"  value="button">
</form>
<a href="?amhref" name="amhref" >Href</a>
<?php
  if(isset($_GET['amhref'])){
    echo ("<h1>I am href </h1>");
  }else if(isset($_POST['button'])){
    echo ("<h1>I am the button</h1>");
  }
?>

Using an <input> control to achieve this. 使用<input>控件来实现此目的。 I have used a hidden control. 我使用了隐藏控件。

<input type="hidden" name="id1" value="hello">

You can't do with an <a> tag 您不能使用<a>标记

tag not element of form type so that you cant pass to in form submite. 标签不是表单类型的元素,因此您不能在表单提交中传递给它。 If you want to pass keep amhref value in input type text or Hidden. 如果要传递,请将amhref值保留在输入类型的文本或“隐藏”中。

You can pass value with href with GET method also. 您也可以使用GET方法通过href传递值。

<form action="test.php" method="post"/>
<input type ="submit" name="button"  value="button">
</form>
<a href="?amhref" name="amhref" >Href</a>

<?php
  if(isset($_GET['amhref'])){
    echo ("<h1>I am href </h1>");
  }else if(isset($_POST['button'])){
    echo ("<h1>I am the button</h1>");
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM