zoukankan      html  css  js  c++  java
  • django 分类搜索(根据不同的单选框,改变form提交的地址)

    前端html部分form

    <form id="searchform" action="#" method="get"  class="navbar-form navbar-left">
                    <label class="radio-inline">
                        <input type="radio" name="searchtype" value="soft" checked>
                        <span style="color: white">软件</span>
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="searchtype" value="shop">
                        <span style="color: white">店铺</span>
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="searchtype" value="task">
                        <span style="color: white">任务</span>
                    </label>
                    <div class="form-group" style="margin-left: 5px">
                        <input type="text" name="keyword" class="form-control" placeholder="软件/店铺/任务">
                    </div>
                        <button type="button" id="searchbutton" class="btn btn-default">搜全站</button>
                </form>

    前端js部分

    <script>
        $(document).ready(function(){
            $("#searchbutton").click(function(){
                var a = $("input[name='searchtype']:checked").val();
                if(a=="soft"){var newUrl = "{% url 'goods:softlist' %}";}
                if(a=="shop"){var newUrl = "{% url 'goods:shoplist' %}";}
                if(a=="task"){var newUrl = "{% url 'goods:tasklist' %}";}
                    //设置新提交地址
                $("#searchform").attr('action',newUrl);    //通过jquery为action属性赋值
                $("#searchform").submit();    //提交ID为myform的表单
            })
        });
    
    </script>
  • 相关阅读:
    视图与URL配置--Hello world
    初始Django
    Django 学习之前提
    MySQL--解决中文乱码
    第二课时之c#语言基础
    第一课时之c#程序设计概述
    hdu--1029--思维题
    hdu--1028--dp||递推||母函数
    hdu--1026--bfs&&优先队列&&打印路径
    hdu--1027-next_permutation||dfs
  • 原文地址:https://www.cnblogs.com/xuepangzi/p/9187958.html
Copyright © 2011-2022 走看看