我有一个主页,其中包含导航侧边栏和搜索栏。如果我修改代码,使搜索工作导航不会工作,反之亦然。继承人的代码。请帮忙
<div class="w3-bar w3-black">
<a href="home.php" class="w3-bar-item w3-button">Home</a>
<a href="msg.php" class="w3-bar-item w3-button">Message</a>
<a href="frnd.php" class="w3-bar-item w3-button">Friends</a>
<a href="notify.php" class="w3-bar-item w3-button">Notification</a>
<div class="w3-dropdown-hover">
<button class="w3-button">Dropdown</button>
<div class="w3-dropdown-content w3-bar-block w3-card-4">
<a href="#" class="w3-bar-item w3-button">Settings</a>
<a href="logout.php" class="w3-bar-item w3-button">Log-Out</a>
</div>
</div>
<form action="result.php" method="GET">
<input type="text" name="query" class="w3-bar-item w3-input" style="color:#000" placeholder="Search.."/>
<button class="w3-bar-item w3-button w3-green">GO</button>
</div>
现在点击导航栏图标。它转到搜索结果。使用GET方法,表单标签导航栏将无法打开。
答案 0 :(得分:2)
您应该关闭表单标记
<form action="result.php" method="GET">
<input type="text" name="query" class="w3-bar-item w3-input" style="color:#000" placeholder="Search.."/>
<button type="submit" class="w3-bar-item w3-button w3-green">GO</button>
</form>
否则表格形式不良,无法提交价值
并将提交类型添加到按钮
答案 1 :(得分:1)
更好的是,您的代码看起来像这样
<div class="w3-bar w3-black">
<a href="home.php" class="w3-bar-item w3-button">Home</a>
<a href="msg.php" class="w3-bar-item w3-button">Message</a>
<a href="frnd.php" class="w3-bar-item w3-button">Friends</a>
<a href="notify.php" class="w3-bar-item w3-button">Notification</a>
<div class="w3-dropdown-hover">
<button class="w3-button">Dropdown</button>
<div class="w3-dropdown-content w3-bar-block w3-card-4">
<a href="#" class="w3-bar-item w3-button">Settings</a>
<a href="logout.php" class="w3-bar-item w3-button">Log-Out</a>
</div>
</div>
<?php if(isset($_GET['query'])): ?>
<form action="result.php" method="GET">
<input type="text" name="query" class="w3-bar-item w3-input" style="color:#000" placeholder="Search.."/>
<button class="w3-bar-item w3-button w3-green">GO</button>
</form>
<?php endif ?>
</div>
希望这个答案可以帮助你解决问题