码迷,mamicode.com
首页 > 其他好文 > 详细

popup demo

时间:2017-12-22 00:29:37      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:pos   head   view   highlight   idt   end   char   function   eth   

Django下实现:

urls.py:

from django.conf.urls import url
from django.contrib import admin
from app01 import views

urlpatterns = [
    url(r‘^admin/‘, admin.site.urls),
    url(r‘^index/‘, views.index),
    url(r‘^pop/‘, views.pop),
]

  

app01.views.py

from django.shortcuts import render


def index(request):
    return render(request,‘index.html‘)

def pop(request):
    if request.method == "GET":
        return render(request, ‘pop.html‘)
    else:
        user = request.POST.get(‘user‘) #这里可以有数据库操作
        return render(request,‘pop_response.html‘,{‘user‘:user})

  

templates.index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1 id="i1">无所谓</h1>
    <a href="#" onclick="popUp(‘http://www.oldboyedu.com‘)">点我点我</a>

    <script>
        function xxxpopupCallback(text) {
            document.getElementById(‘i1‘).innerHTML = text;
        }
        function popUp(url) {
            window.open( ‘/pop/‘, ‘/pop/‘ ,"status=1, height:500, width:600, toolbar=0, resizeable=0");
        }
        
    </script>
</body>
</html>

  

templates.pop.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form method="post">
        {% csrf_token %}
        <input type="text" name="user">
        <input type="submit" value="保存">
    </form>
</body>
</html>

  

templates.pop_response.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>正在关闭</h1>
    <script>
        (function () {
            // 可以调用popup原页面的一个函数
            opener.xxxpopupCallback("{{ user }}");
            window.close();
        })()
        
        
    </script>
</body>
</html>

  

 

popup demo

标签:pos   head   view   highlight   idt   end   char   function   eth   

原文地址:http://www.cnblogs.com/wangbaihan/p/8082759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!