一、作用

用于使浏览器自动生成弹窗

二、示例

1、新建Django项目,新建APP:app01, 项目根目录下新建文件夹static

2、静态文件配置,在settings.py中配置static:

3、路由配置, urls.py:

from django.contrib import admin
from django.urls import path
from app01 import views urlpatterns = [
path('admin/', admin.site.urls),
path('index/', views.index),
path('add/city/', views.add_city),
]

4、编写view函数,views.py:

from django.shortcuts import render, HttpResponse

def index(request):
"""首页"""
return render(request, "index.html", locals()) def add_city(request):
"""添加城市""" if request.method == "POST":
# 获取数据 存入数据库
# ........
city_info = {"id": 5, "city": "成都"}
return render(request, "pop-response.html", locals()) # 新建完成后自动关闭窗口
return render(request, "add_city.html")

5、templates模板编写:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form>
<p><input type="text"></p>
<p>
<select id="city">
<option value=1>北京</option>
<option value=2>天津</option>
<option value=3>上海</option>
<option value=4>深圳</option>
</select>
<input type="button" value="+" onclick="popUp();">
</p>
</form> <script>
function func(cityId, cityTitle){
//构造一个option标签
var tag = document.createElement("option");
tag.value = cityId;
tag.innerText = cityTitle;
//找到select框 将option添加进去
var city = document.getElementById("city");
city.appendChild(tag);
} function popUp() {
//打开新弹窗 (弹窗地址,弹窗名, 弹窗格式设置)
window.open("/add/city/", "x1", "status=1, height=500, width=500, toolbar=0, resizeable=0"); }
</script>
</body>
</html>

add_city.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box {
width: 200px;
height: 200px;
border: 1px solid dodgerblue;
}
</style>
</head>
<body>
<h3>新建城市</h3>
<div class="box">
<form method="post">
{% csrf_token %}
<input type="text" name="city">
<input type="submit" value="提交">
</form>
</div>
</body>
</html>

pop-response.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正在关闭</title>
</head>
<body> <script src="/static/commons.js"></script>
{#引入文件,里面的'{{ id }}'不会被识别,就只是把它当做普通的字符串打印出来#} <script> //function close(){
//window.close();
//}
//close(); // 自执行函数 在写完函数后, 后面直接加括号便可以执行,括号内可以传递参数, 执行效果同上
(function(){
// 获取到是谁把这个页面打开的
opener.func({{ id }}, "{{ city }}"); //传递参数 {"id": 5, "city": "成都"} window.close();
})(); // 可以传参:
//(function(arg){ //})("x1") // arg=x1
</script>
</body>
</html>

6、static文件夹下新建文件commons.js:

alert('{{id}}');  //在pop-response.html中引入它

7、启动项目,在浏览器输入:http://127.0.0.1:8088/index/进入首页,点击按钮弹出新窗口,新增城市,提交后窗口自动关闭

popup介绍的更多相关文章

  1. 重新想象 Windows 8 Store Apps 系列文章索引

    [源码下载][重新想象 Windows 8.1 Store Apps 系列文章] 重新想象 Windows 8 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  2. 重新想象 Windows 8.1 Store Apps 系列文章索引

    [源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  3. Windows 8 Store Apps

    重新想象 Windows 8 Store Apps 系列文章索引 Posted on 2013-11-18 08:33 webabcd 阅读(672) 评论(3) 编辑 收藏 [源码下载] 重新想象 ...

  4. 34.qt quick-Popup弹出窗口自定义

    1.Popup介绍 Popup是一个弹出窗口的控件它的常用属性如下所示: anchors.centerIn : Object,用来设置居中在谁窗口中. closePolicy : enumeratio ...

  5. popup定位引擎popper.js介绍

    https://medium.com/@FezVrasta/popper-js-v1-5e8b3acd888c https://survivejs.com/blog/popper-interview/ ...

  6. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  7. 网页引导:jQuery插件实现的页面功能介绍引导页效果

    现在很多网站不仅是介绍,更多的是有一些功能,怎么样让客户快速的知道网站有哪些功能呢?这里pagewalkthrough.js插件能帮我们实现,它是一个轻量级的jQuery插件,它可以帮助我们创建一个遮 ...

  8. 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup

    [源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...

  9. jQuery Mobile 1.1八大新特性介绍

    随着HTML 5时代的来临,移动开发开始进入了一个新的时代,现在只需要懂得HTML5,配合一定的开发框架,就可以开发出十分漂亮的HTML5的移动应用.在众多的 移动HTML5开发框架中,比较著名的是j ...

随机推荐

  1. ______________从时间超限到800ms 到200ms——————2098

    分拆素数和 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted S ...

  2. Microsoft函数调用约定

    Microsoft函数调用约定 对于所有调用共有的约定:ebx.ebp.esi.edi都是calle-save,即由被调用的函数负责它们的保存(如果被调用函数用到了这些寄存器的话) 先看函数调用发生了 ...

  3. C#课程设计

    一.问题描述 监视文件和文件夹的变化(FileSystemWatcher 类):选择一个文件夹,单击"开始监视",该文件夹处于监视状态,此时对该文件夹如果进行操作,这些行为将显示出 ...

  4. ArrayList、HashMap 与 员工类(程序员、经理的结合使用) 相当于集合与继承的总结

    package Day28ketangzuoye; import java.util.ArrayList; import java.util.HashMap; import java.util.Map ...

  5. Python 相关疑问

    1. 如果我的脚本error handling 做的好,在ctrl+c退出的时候是不是不应该有任何traceback log? 2. repr() str() eval() 之间的区别? 3. 参数传 ...

  6. Codeforces Beta Round #96 (Div. 2) (A-E)

    写份DIV2的完整题解 A 判断下HQ9有没有出现过 #include <iostream> #include<cstdio> #include<cstring> ...

  7. sqlServer备份和还原语句

    数据库备份语句和还原语句: --完整备份 Backup Database xxx To disk=’G:\Backup\xxx.bak’ --查看物理路径 restore filelistonly f ...

  8. CentOS 7 下配置 firewalld(firewall-cmd)实现 NAT 转发 软路由

    如果配合 DHCP 服务或实现更多功能. ☼ NAT 转发软路由 开启 NAT 转发之后,只要本机可以上网,不论是单网卡还是多网卡,局域网内的其他机器可以将默认网关设置为已开启 NAT 转发的服务器 ...

  9. 阿里云ecs绑定域名

    在阿里云服务器ECS一切配置ok后,通过域名一直访问不成功,结果发现还需要在后台进行安全组的规则设定:

  10. hibernate 批量插入数据

    如题,有两种方法 1)使用FLUSH 2)使用JDBC 分别来解释: 1)hibernate在进行数据库操作的时候,都要有事务支持的.可能你曾遇到过,没有加事务,程序会报错的情况. 而事务每次提交的时 ...