我有多个复选框,并且 onClick 我正在将值发送到 URL 并从 PHP 中的 URL 获取值,以便我可以从查询中选择结果。
如果我选择美国和国际市场,则 URL 为“product.php?market=US” 但当我选择瓷砖和平板时,它会显示“product.php?market=US-International&type=tiles&type=slabs” 当我返回并再次选择市场为国际后,它显示“product.php?market=US&type=tiles&type=slabs&market=International”
我如何管理 URL 中的获取值,例如 daraz.pk/women/clothing/kurtas-shalwar-kameez/在左侧过滤器上执行的操作。
复选框结构:
市场:
美国 国际
类型:
瓷砖 板
类别:
奥尼克斯 等等
CODE :
<div class="widgetTitle">
<h3 class="garis">Market</h3>
<div class="productsline"></div>
</div>
<nav class="categories">
<input name="check_list[]" onclick="window.location.href = '?market=Pakistan'" type="checkbox" id="checkbox-1" class="regular-checkbox" /><label for="checkbox-1"></label>
<input name="check_list[]" onclick="window.location.href = '?International&'" type="checkbox" id="checkbox-2" class="regular-checkbox" /><label for="checkbox-2"></label>
International
</nav>
</div>
<div class="widgetTitle">
<h3 class="garis">Type</h3>
<div class="productsline"></div>
</div>
<nav class="categories">
<input name="check_list[]" onclick="window.location.href = '&type=blocks'" type="checkbox" id="checkbox-3" class="regular-checkbox" /><label for="checkbox-3"></label>
Blocks
<input name="check_list[]" onclick="window.location.href = '<?=$path;?>&type=slabs'" type="checkbox" id="checkbox-4" class="regular-checkbox" /><label for="checkbox-4"></label>
Slabs
<input name="check_list[]" onclick="window.location.href = '&type=tiles'" type="checkbox" id="checkbox-5" class="regular-checkbox" /><label for="checkbox-5"></label>
Tiles
<input name="check_list[]" onclick="window.location.href = '&type=mosaics'" type="checkbox" id="checkbox-6" class="regular-checkbox" /><label for="checkbox-6"></label>
Mosaics
</nav>
</div>
最佳答案
您是使用 php 还是 javascript 构建 url?
使用 PHP:
$_GET['market'] = 'your new market';
echo http_build_query( $_GET );
编辑后:
onClick="?<?php echo http_build_query( array('market' => 'Pakistan') + $_GET ); ?>"
关于PHP 获取 URL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19949024/