jQuery根据复选框单击类别重定向到特定URL [英] jQuery redirect to specific URL based on checkbox click category

查看:83
本文介绍了jQuery根据复选框单击类别重定向到特定URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有多个类别可以过滤搜索.

I have an multiple category on my page to filter search.

http://localhost/shop/category/produkunggulan/CT0002

示例我具有此类别:

品牌

$qBrandList = mysqli_query($con, "SELECT P.productid, P.brandid_fk, B.Brandid, B.brand_name FROM tb_product P, tb_brand B WHERE P.brandid_fk = B.brandid AND P.categoryid_fk LIKE '%" . $getCategoryID . "%' GROUP BY B.brandid ORDER BY B.brand_name ASC");
while($dBrandList = mysqli_fetch_array($qBrandList))
{
?>
    <div><label><input name="chkBrand[]" class="chkBrand" type="checkbox" value="<?php echo $dBrandList['brandid_fk']; ?>"/> <?php echo $dBrandList['brand_name']; ?></label></div>
<?php
}

折扣

<label><input type="checkbox" name="discount" value="Y"/> Diskon</label>

现在,我要在用户单击复选框时将其直接重定向到包含类别键(每次单击复选框)的url,并在未选中的情况下删除该值.

Now I want when user click the checkbox, it will be directly redirect to the url including the key of category (every click checkbox) and remove the value if uncheck.

示例我单击EMORI,然后单击FOSSIL,因此URL应为:

Example I click EMORI then FOSSIL, so the URL should be:

http://localhost/shop/category/produkunggulan/CT0002?brand=BR0003,BR0010

推荐答案

<label><input type="checkbox" name="discount" value="Y"/> Diskon</label>

我认为您不需要使用复选框进行重定向.只需使用输入类型'submit'.

I don't think you need to use a checkbox to redirect. Simply use input type 'submit'.

<label><input type="submit" name="discount" value="Diskon"/> 

或添加onchange事件以提交

or add onchange event to submit

<label><input type="checkbox" onChange="this.form.submit()" name="discount" value="Y"/> Diskon</label>

还使用标记中的'get'方法在url上显示数据.

also use 'get' method in the tag to show your data at url.

可以肯定的是,您的网址看起来不会像您提到的那样,而是看起来像是

One thing for sure your url wont look as you mentioned rather that it will look as

http://localhost/shop/category/produkunggulan/CT0002?chkBrand%5B%5D=BR0003& chkBrand%5B%5D=BR0010

%5B代表'[',%5D代表']'.

Here %5B is for'[' and %5D is for ']'.

这篇关于jQuery根据复选框单击类别重定向到特定URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆