简体   繁体   English

href命名并传递$ _GET变量

[英]href to name and pass $_GET variable

I have to links: 我必须链接:

<a href="page2.php#anchor1">link 1</a>
<a href="page2.php#anchor2">link 2</a>

However, I want to add an extra parameter, link so: 但是,我想添加一个额外的参数,链接为:

<a href="page2.php#form?type=small">link 1</a>
<a href="page2.php#form?type=large">link 2</a>

Using php, I need to check if my $_GET isset, I need to use it to control an element in my form, like so: 使用php,我需要检查$_GET是否已设置,我需要使用它来控制表单中的元素,如下所示:

<select id="type" name="type">
    <option value="sm" <?php if(isset($_GET['type']) and ($_GET['type'] == "small")) { echo 'selected="selected"'; } ?>>Small</option>
    <option value="lg" <?php if(isset($_GET['type']) and ($_GET['type'] == "large")) { echo 'selected="selected"'; } ?>>Large</option>
</select>

Important details 重要细节

  • If this is important, I am using my .htaccess to remove the .php extension; 如果这很重要,我将使用.htaccess删除.php扩展名; could that be a factor? 这可能是一个因素吗?
  • Page 2 can be accessed without filling in Page 1, but is not required; 无需填写第1页就可以访问第2页,但这不是必需的。 If none is set from the $_GET, none should be selected, otherwise, the proper value should be selected. 如果未从$ _GET设置任何内容,则应选择任何内容,否则应选择适当的值。

查询字符串必须位于片段标识符之前

page2.php?type=small#form

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

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