zoukankan      html  css  js  c++  java
  • popup

    from django.shortcuts import render,HttpResponse
    from django.urls import reverse
    # Create your views here.
    
    from app01 import models
    
    
    def test(request):
        user_group_list = models.UserGroup.objects.all()
    
        return render(request,'test.html',{'user_group_list':user_group_list})
    
    def add_test(request):
        if request.method == "GET":
            return render(request,'add_test.html')
        else:
            popid = request.GET.get('popup')
            if popid:
                # 通过popup新创建了一个页面进来
                title = request.POST.get('title')
                obj = models.UserGroup.objects.create(title=title)
                # response = {'id':obj.id,'title': obj.title}
                # 1. 关闭popup页面
                # 2. 将新增的数据添加,传送到原来发送pop页面中的ugID标签位置 popid = ugID
                return render(request,'popup_response.html',{'id':obj.id,'title':obj.title,'popid':popid })
            else:
                title = request.POST.get('title')
                models.UserGroup.objects.create(title=title)
                return HttpResponse('重定向列表页面:所有用户组')
    Views.py
    from django.conf.urls import url,include
    from django.contrib import admin
    from app01 import views
    from yingun.service import v1
    
    urlpatterns = [
    
    
        url(r'^test/',views.test),
        url(r'^add_test/',views.add_test),
        
    ]
    urls.py
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <p>用户名: <input type="text"></p>
        <p>用户组:
            <select  id="ugID">
            {% for row in user_group_list %}
                <option value="{{ row.pk }}">{{ row.title }}</option>
            {% endfor %}
            </select>
            <a href="#" onclick="popupUrl('/add_test/?popup=ugID')">增加</a>
        </p>
    
        <script>
            function popupUrl(url) {
                window.open(url,"xxxxxx","status=1,height:500,600,toolbar=0,resizeable=0");
            }
            function popupCallBackl(popid,id,title) {
                var tag = document.createElement("option");
                tag.innerText = title;
                tag.setAttribute("value",id);
                tag.setAttribute("selected","selected");
                var selectid = document.getElementById(popid);
                selectid.appendChild(tag);
            }
        </script>
    
    </body>
    </html>
    test.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <h1>增加测试数据</h1>
        <form action="" method="post">
            {% csrf_token %}
            <input type="text" name="title">
            <input type="submit" value="提交">
        </form>
    </body>
    </html>
    add_test.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>正在关闭的pop页面</title>
    </head>
    <body>
    
        <script>
            //将数据创送给发起popup的页面
            opener.popupCallBackl('{{ popid }}','{{ id }}','{{ title }}');
            window.close();
        </script>
    
    </body>
    </html>
    popup_responde.html
  • 相关阅读:
    2020.8.20收获
    2020.8.19
    2020.8.21收获
    2020.8.24收获
    UIScrollView滑动动作结束的侦听函数
    iphone 自定义UISwitch
    总结SQLite不支持的SQL语法有哪些
    去除nsstring中的空格
    ObjectiveC中判断字符串是否包含其他字符串
    设置IPHONE顶部的状态栏的样式
  • 原文地址:https://www.cnblogs.com/golangav/p/7526238.html
Copyright © 2011-2022 走看看