【问题标题】:How to make GET from "field=foo&field=bar" to "field=foo,bar"如何使 GET 从 "field=foo&field=bar" 到 "field=foo,bar"
【发布时间】:2019-08-30 08:05:45
【问题描述】:

我有一个包含许多字段的 html 表单:

<form action="" method="get">
...
<input type="checkbox" name="price" id="price-1000" value="1000">
<input type="checkbox" name="price" id="price-2000" value="2000">
<input type="checkbox" name="price" id="price-3000" value="3000">
...
<input type="submit" value="send">
</form>

在检查和发送时,我有以下查询字符串:?price=1000&amp;price=2000

如何在浏览器网址中设置?price=1000,2000

我认为我需要通过 htaccess 重写规则?还是有其他方法?

【问题讨论】:

标签: php .htaccess url-rewriting get


【解决方案1】:

使用Jquery就可以了。

index.php

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<form action="redex.php" method="get">
<input type="checkbox" id="price-1000" value="1000" class="ckbox">
<input type="checkbox" id="price-2000" value="2000" class="ckbox">
<input type="checkbox" id="price-3000" value="3000" class="ckbox">
<input type="hidden" name="price" id="price-1000" value="1000" class="ckvalues">
<input type="submit" value="send">
</form>
<script type="text/javascript">
    $(document).ready(function() {
        var favorite = [];
        $('.ckbox').change(function() {
            $.each($("input[type='checkbox']:checked"), function(){            
                favorite.push($(this).val());
            });
            var str1 = favorite.toString()
            $('.ckvalues').val(str1)
            favorite.length = 0;
        });

    });
</script>

redex.php

<?php
echo $_GET['price'];
?>

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-04
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 2010-12-09
    • 2017-06-23
    相关资源
    最近更新 更多