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

关于popup

时间:2017-10-23 23:11:32      阅读:385      评论:0      收藏:0      [点我收藏+]

标签:site   attr   ace   function   click   ntb   ken   var   开启   

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>
 

关于popup

标签:site   attr   ace   function   click   ntb   ken   var   开启   

原文地址:http://www.cnblogs.com/jec1999/p/7719561.html

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