p1.html:点击添加按钮,开启窗口,打开p2.html,填写数据后返回p3.html,p3.html将数据回传到p1.html,且关闭自己
p1.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<select name="" id="s1">
<option value="">北京</option>
<option value="">天津</option>
</select>
<button onclick="add()">添加</button>
<script>
function add() {
window.open('/p2/',"dsdsd","status=1,height:500,width:600,toolbar=0,resizeable=0")
}
function xxxxxxxx(name) {
var option = document.createElement("option")
option.innerHTML=name
option.setAttribute("selected",true)
document.getElementById("s1").appendChild(option)
}
</script>
</body>
</html>
def p2(request):
if request.method=='GET':
return render(request,"p2.html")
elif request.method=='POST':
obj = models.UserGroup.objects.create(title=request.POST.get("city"))
return render(request,"p3.html",{"obj":obj})
urlpatterns = [
url(r'^nb/', v1.site.urls),
url(r'^p1/', p1),
url(r'^p2/', p2),
]
p2.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post">
{% csrf_token %}
<input name="city" type="text">
<input type="submit" value="提交">
</form>
</body>
</html>
p3.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正在返回</title>
</head>
<body>
<script>
(function () {
var name = "{{ obj.title }}";
window.opener.xxxxxxxx(name);
window.close()
})()
</script>
</body>
</html>