popup介绍
一、作用
用于使浏览器自动生成弹窗
二、示例
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介绍的更多相关文章
- 重新想象 Windows 8 Store Apps 系列文章索引
[源码下载][重新想象 Windows 8.1 Store Apps 系列文章] 重新想象 Windows 8 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...
- 重新想象 Windows 8.1 Store Apps 系列文章索引
[源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...
- Windows 8 Store Apps
重新想象 Windows 8 Store Apps 系列文章索引 Posted on 2013-11-18 08:33 webabcd 阅读(672) 评论(3) 编辑 收藏 [源码下载] 重新想象 ...
- 34.qt quick-Popup弹出窗口自定义
1.Popup介绍 Popup是一个弹出窗口的控件它的常用属性如下所示: anchors.centerIn : Object,用来设置居中在谁窗口中. closePolicy : enumeratio ...
- popup定位引擎popper.js介绍
https://medium.com/@FezVrasta/popper-js-v1-5e8b3acd888c https://survivejs.com/blog/popper-interview/ ...
- 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
[源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...
- 网页引导:jQuery插件实现的页面功能介绍引导页效果
现在很多网站不仅是介绍,更多的是有一些功能,怎么样让客户快速的知道网站有哪些功能呢?这里pagewalkthrough.js插件能帮我们实现,它是一个轻量级的jQuery插件,它可以帮助我们创建一个遮 ...
- 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup
[源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...
- jQuery Mobile 1.1八大新特性介绍
随着HTML 5时代的来临,移动开发开始进入了一个新的时代,现在只需要懂得HTML5,配合一定的开发框架,就可以开发出十分漂亮的HTML5的移动应用.在众多的 移动HTML5开发框架中,比较著名的是j ...
随机推荐
- 【OCR技术系列一】光学字符识别技术介绍
注:此篇内容主要是综合整理了光学字符识别 和OCR技术系列之一]字符识别技术总览,详情见文末参考文献 什么是 OCR? OCR(Optical Character Recognition,光学字符识别 ...
- HTML_CSS入门学习
1 HTML 简介 下面解释什么是HTML,以及HTML标签和HTML文档的含义. 1.1 什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Te ...
- [POI2011]Temperature
Description The Byteotian Institute of Meteorology (BIM) measures the air temperature daily. The mea ...
- Hdu 5416 CRB and Tree (bfs)
题目链接: Hdu 5416 CRB and Tree 题目描述: 给一棵树有n个节点,树上的每条边都有一个权值.f(u,v)代表从u到v路径上所有边权的异或值,问满足f(u,v)==m的(u, v) ...
- http缓存之lastModified和etag
1.cache-control 访问资源 首次访问页面时间:2018.2.1 9:56 (当前时间=GMT时间+8h) 缓存时长max-age:1 day Expire缓存失效时间:2018.2. ...
- 08 H5新增input元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- AJPFX关于this用法和注意事项
this:代表对象.就是所在函数所属对象的引用.哪个对象调用了this所在的函数,this就代表哪个对象,就是哪个对象的引用.开发时在定义功能时,如果该功能内部使用到了调用该功能的对象,这时就用thi ...
- AJPFX学习笔记JavaAPI之String类
学习笔记JavaAPI之String类 [size=10.5000pt]一.所属包java.lang.String,没有子类.特点:一旦被初始化就不可以被改变. 创建类对象的两种方式: String ...
- Oracle Mysql的jdbc连接
Oracle和MySql的jdbc或连接池中的连接,写下来以便随时参考 Oracle: driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc ...
- R in action读书笔记(6)-第七章:基本统计分析(中)
7.2 频数表和列联表 > library(vcd) > head(Arthritis) ID Treatment Sex Age Improved 1 57 Treated Male 2 ...