Javascript 获取URL以确定复选框的值

Javascript 获取URL以确定复选框的值,javascript,php,html,wordpress,hashchange,Javascript,Php,Html,Wordpress,Hashchange,我环顾四周,没有发现任何关于如何做这件事的有用信息,如果这是一个重复的问题,那么很抱歉 我试图得到它,所以如果用户点击某个链接,他们将被发送到一个预先选中复选框的页面 例如,我有3个类别 PSHE、食品和EHWB 我有一个页面,上面所有的帖子都有这些类别,但是过滤器只显示所选的类别 我想在主页上有3个链接,如果点击,加载相应的链接预先选中复选框的页面 最好的方法是什么 到目前为止,我所没有发现的是: $('input[type=checkbox').click(function(){ win

我环顾四周,没有发现任何关于如何做这件事的有用信息,如果这是一个重复的问题,那么很抱歉

我试图得到它,所以如果用户点击某个链接,他们将被发送到一个预先选中复选框的页面

例如,我有3个类别

PSHE、食品和EHWB

我有一个页面,上面所有的帖子都有这些类别,但是过滤器只显示所选的类别

我想在主页上有3个链接,如果点击,加载相应的链接预先选中复选框的页面

最好的方法是什么

到目前为止,我所没有发现的是:

$('input[type=checkbox').click(function(){
  window.location.hash = $(this).val();

});
这是点击URL时复选框的值,我不确定这是否是一个声明点,但任何帮助都将不胜感激。谢谢

编辑:

这是我要求的HTML

        <fieldset id="filters" class="form__section form__section--group form__section--categories">

          <legend class="form__section__title">
            <h2 class="form__section__title__text">Filter by category:</h2>
          </legend>

              <div class="form__item form__item--boolean form__item--checkbox">
                <button type="button" value=".all" id="checkAll">All</button>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-food" value=".category-what-food" id="category-what-food ff-checkbox-1" class="checkbox1" /><label for="category-what-food ff-checkbox-1">Food</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-pshe" value=".category-what-pshe" id="category-what-pshe ff-checkbox-2" class="checkbox1" /><label for="category-what-pshe ff-checkbox-2">PSHE</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-sex-education" value=".category-what-sex-education" id="category-what-sex-education ff-checkbox-3" class="checkbox1" /><label for="category-what-sex-education ff-checkbox-3">Sex Education</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-physical-education" value=".category-what-physical-education" id="category-what-physical-education ff-checkbox-4" class="checkbox1" /><label for="category-what-physical-education ff-checkbox-4">Physical Education</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-ehwb" value=".category-what-ehwb" id="category-what-ehwb ff-checkbox-5" class="checkbox1" /><label for="category-what-ehwb ff-checkbox-5">EHWB</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-environment" value=".category-what-environment" id="category-what-environment ff-checkbox-6" class="checkbox1" /><label for="category-what-environment ff-checkbox-6">Environment</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-policies" value=".category-what-policies" id="category-what-policies ff-checkbox-7" class="checkbox1" /><label for="category-what-policies ff-checkbox-7">Policies</label>
              </div><!--/form__item-->
              <div class="form__item form__item--boolean form__item--checkbox">
                <input type="checkbox" name="ff-checkbox category-what-governors" value=".category-what-governors" id="category-what-governors ff-checkbox-8" class="checkbox1"  /><label for="category-what-governors ff-checkbox-8">Governors</label>
              </div><!--/form__item-->

        </fieldset><!--/form__group-->

按类别筛选:
全部的
食物
PSHE
性教育
体育
EHWB
环境
政策
州长

是的,哈利,你的说法是正确的。而不是将复选框值指定给位置哈希。编写条件语句以指定要打开的所需url本身

$('input[type=checkbox]').click(function() {
    var x = $(this).val();
    if (x == "cond 1") {
        window.open("url1", "_self");
    } else if (x == "cond2") {
        window.open("url2", "_self"); //and so on
    }
});

希望能有帮助

也向我们显示您的html为什么不将其作为查询字符串中的数据参数发送?如果您将第一个链接设置为:而不是在somepage.php上,如果(isset($\u GET['Food'])echo checked
$('input[type=checkbox'),则可以设置条件
这里缺少一些东西???@ManishPuri如果这也行的话,你介意告诉我怎么做吗?谢谢你的回复。谢谢你的回复!你能帮我把我需要的东西放进去吗,再次感谢。:)例如:如果(x=”。分类什么食物“{window.open(“correspondingurl”),“\u self”)}否则,如果(x==“.category what pshe”){window.open(“correspondingurl”,“_self”)}//等等,如果动态生成url,还可以将值作为#param追加到url