php - 如何使 GET 从 "field=foo&field=bar" 到 "field=foo,bar"
问题描述
我有一个包含许多字段的 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&price=2000
如何?price=1000,2000
在浏览器 URL 中创建
我想我需要通过 htaccess 重写规则?还是有其他方法?
解决方案
使用 Jquery 将是可能的。
索引.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'];
?>
愿这对你有所帮助。
推荐阅读
- mysql - 升级到 MySQL 8。从服务器接收到字段“255”的未知字符集索引。例外
- class - 初始化 JAXB 以解组到外部类定义
- python - Pyinstaller - 多个 python 脚本
- javascript - 关闭浏览器窗口,其中单击按钮时的角度应用程序
- javascript - 将组件定位在 .jsx 文件中,而不是通过 .css 文件
- xml - 为什么从 XML 导入 Access 数据库时数据会被截断
- python-3.x - 出现错误“无法导入 PIL.Image。使用 `array_to_img` 需要 PIL。”
- hashicorp-vault - Vault,如何强制在特定策略下创建令牌?
- reactjs - 在没有 Redux 的兄弟姐妹之间传递数据
- python-sphinx - :ref: 链接不给链接