所以基本上我可以说我有一个名为 page-with-links.php 的页面:
<ul>
<li><a href="page-with-checkboxes.php" name="blue">Blue</a></li>
<li><a href="page-with-checkboxes.php" name="red">Red</a></li>
<li><a href="page-with-checkboxes.php" name="green">Green</a></li>
<li><a href="page-with-checkboxes.php" name="yellow">Yellow</a></li>
<li><a href="page-with-checkboxes.php" name="orange">Orange</a></li>
</ul>
和一个名为 page-with-checkboxes.php 的页面:
<h3>You selected:</h3>
<form>
<input type="checkbox" name="blue" />
<label for="blue"> Blue</label><br>
input type="checkbox" name="red" />
<label for="red"> Red</label><br>
input type="checkbox" name="green" />
<label for="green"> Green</label><br>
<input type="checkbox" name="yellow" />
<label for="yellow"> Yellow</label><br>
<input type="checkbox" name="orange" />
<label for="orange"> Orange</label><br>
</form>
我希望能够使用<a>
标记的名称值来检查下一页的相关框。
例如,如果用户点击 page-with-links.php 上的“绿色”,我希望在页面时检查name="green"
的复选框-checkboxes.php 加载。
我希望我已经足够清楚了。提前感谢任何可以提供帮助的人!
答案 0 :(得分:1)
a
代码属性不会影响请求。
你必须遵循这个:
<ul>
<li><a href="page-with-checkboxes.php?name=blue" name="blue">Blue</a></li>
<li><a href="page-with-checkboxes.php?name=red" name="red">Red</a></li>
<li><a href="page-with-checkboxes.php?name=green" name="green">Green</a></li>
<li><a href="page-with-checkboxes.php?name=yellow" name="yellow">Yellow</a></li>
<li><a href="page-with-checkboxes.php?name=orange" name="orange">Orange</a></li>
</ul>
在page-with-checkboxes.php
获取此值:
<?php
if(isset($_GET['name']) {
$color = $_GET['name'];
} else {
$color = null;
}
?>
<form>
<input type="checkbox" name="blue" <?php print $color=="blue" ? "checked" : "" ?> />
<label for="blue"> Blue</label><br>
input type="checkbox" name="red" <?php print $color=="red" ? "checked" : "" ?> />
<label for="red"> Red</label><br>
input type="checkbox" name="green" <?php print $color=="green" ? "checked" : "" ?> />
<label for="green"> Green</label><br>
<input type="checkbox" name="yellow" <?php print $color=="yellow" ? "checked" : "" ?> />
<label for="yellow"> Yellow</label><br>
<input type="checkbox" name="orange" <?php print $color=="orange" ? "checked" : "" ?> />
<label for="orange"> Orange</label><br>
</form>
答案 1 :(得分:0)
你能试试吗,
在page-with-links.php中:
<li><a href="page-with-checkboxes.php?type=blue" name="blue">Blue</a></li>
在page-with-checkboxes.php中:
<input type="checkbox" name="blue" <?php echo $_GET['type']=='blue'?'checked':''; />
<label for="blue"> Blue</label><br>
答案 2 :(得分:0)
在您的网页上编写代码行 page-with-links.php
<ul>
<li> <a href="page-with-checkboxes.php?value=blue" name="blue">Blue</a> </li>
<li> <a href="page-with-checkboxes.php?value=red" name="red">Red</a></li>
<li> <a href="page-with-checkboxes.php?value=green" name="green">Green</a></li>
<li> <a href="page-with-checkboxes.php?value=yellow" name="yellow">Yellow</a></li>
<li> <a href="page-with-checkboxes.php?value=orange" name="orange">Orange</a></li>
</ul>
并在名为 page-with-checkboxes.php的页面上编写以下代码行:
<input type="checkbox" name="blue" <?php echo $_GET['value']=='blue'?'checked':''; />
<label for="blue"> Blue</label><br>
<input type="checkbox" name="red" <?php echo $_GET['value']=='red'?'checked':''; />
<label for="red"> Red</label><br>
<input type="checkbox" name="green" <?php echo $_GET['value']=='green'?'checked':''; />
<label for="green"> Green</label><br>
<input type="checkbox" name="yellow" <?php echo $_GET['value']=='yellow'?'checked':''; />
<label for="yellow"> Yellow</label><br>
<input type="checkbox" name="orange" <?php echo $_GET['value']=='orange'?'checked':''; />
<label for="orange"> Orange</label>