input按钮选择功能

 <p>
          <input type="checkbox" class="ischecked" id="is_pinkage" name="" value="" <?php if($request->input('is_pinkage') == '1'): ?>checked <?php endif; ?>  />包配送
  
<input type="checkbox" class="ischecked" id="is_24h" name="" value="" <?php if($request->input('is_24h') == '1'): ?>checked <?php endif; ?> />24小时内发货  
<input type="checkbox" class="ischecked" id="is_7goodsreturn" name="" value="" <?php if($request->input('is_7goodsreturn') == '1'): ?>checked <?php endif; ?> />7+天包退
  
<input type="checkbox" class="ischecked" id="is_15renew" name="" value="" <?php if($request->input('is_15renew') == '1'): ?>checked <?php endif; ?> />15+天换新  
<input type="checkbox" class="ischecked" id="is_aftermarket" name="" value="" <?php if($request->input('is_aftermarket') == '1'): ?>checked <?php endif; ?> />售后保障 
 
<input type="checkbox" class="ischecked" id="is_wholesale" name="" value="" <?php if($request->input('is_wholesale') == '1'): ?>checked <?php endif; ?> />批发   </p>

 

js代码

<script type="text/javascript">
    $(".ischecked").click(function(){
    //当点击按钮处于checked则跳转
        if($(this).is(":checked")){
            var add;
            var url = location.search;
            if (url.indexOf("?") != -1) {
               add = window.location.href + "&" + $(this).attr('id') + "=1";
            }else{
               add = window.location.href + "?" + $(this).attr('id') + "=1";
            }
            window.location.href = add;
        }else{
          //当点击按钮处于非checked则跳转
            var url1 = window.location.href;
            var ref = $(this).attr('id');
            var add2 = delQueStr(url1,ref);
            window.location.href = add2;
        }
    })

    function delQueStr(url, ref) {
    //根据跳转情况删除相应的字段
        var str = "";
        if (url.indexOf('?') != -1) {
            str = url.substr(url.indexOf('?') + 1);
        }
        else {
            return url;
        }
        var arr = "";
        var returnurl = "";

        if (str.indexOf('&') != -1) {
            arr = str.split('&');
           for (i in arr) {
                if (arr[i].split('=')[0] != ref) {
                    returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&";
                }
            }
            return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1);
        }
        else {
            arr = str.split('=');
            if (arr[0] == ref) {
                return url.substr(0, url.indexOf('?'));
            }
            else {
                return url;
            }
        }
    }

</script>

 

posted @ 2015-10-23 16:41  午时的海  阅读(505)  评论(0编辑  收藏  举报