/**
*createTime:2015-09-13
*updateTime:2015-09-13
*author:刘俊
*phone:13469119119
*QQ:418873053
**/
var url='/index.php?m=formguide&c=index&a=show&formid=21&ajax=1'; //构建买家报名和卖家报名表单
var formStr = '<li class="clearfix"><div class="optTit fl">买家联系人:</div><div class="option fl"><input id="uname" name="info[uname]" type="text" />';
formStr += '<label class="namelabel" for="uname">请填联系人真实姓名</label></div></li>';
formStr += '<li class="clearfix"><div class="optTit fl">联系电话:</div>';
formStr += '<div class="option fl"><input id="tel" name="info[contact]" type="tel" /><label class="tellabel" for="tel">请填联系人手机号码</label></div></li>';
formStr += '<li class="clearfix"><div class="optTit fl">公司名称:</div>';
formStr += '<div class="option fl"><input id="company" name="info[company]" type="text" /><label class="companylabel" for="company">请填贵公司名称</label></div></li>';
formStr += '<li class="clearfix"><div class="optTit fl">产品要求:</div>';
formStr += '<div class="option fl" style="height:180px"><textarea id="demand" name="info[demand]"></textarea><label class="demandlabel" for="demand">请填写对卖家产品的要求</label></div></li>';
formStr += '<li class="clearfix"><div class="optTit fl">&nbsp;</div><div class="option fl"><a href="javascript:void(0);" class="okbtn font16 mt10 white tc">提交</a></div></li>';
formStr += '</ul></form></div>';
//买家地址
var htmlStr = '<div class="myform"><form id="myform" action="'+url+'" method="post" name="myform"><input name="info[usertype]" value="1" type="hidden" /><ul>';
htmlStr += formStr; //卖家地址
var htmlStr2 = '<div class="myform"><form id="myform" action="'+url+'" method="post" name="myform"><input name="info[usertype]" value="2" type="hidden" /><ul>';
htmlStr2 += formStr; //自定义弹出层
/*$("#toApply").click(function(){
layer.open({
type: 1,
title: "买家报名",
closeBtn: true,
shadeClose: true,
area:['500px','500px'],
skin: 'buyerBox',
content:htmlStr
});
//表单文本框提示文字
$("#myform input,#myform textarea").on({
focus:function(){$(this).next("label").hide();$(this).css("border-color","#999")},
blur:function(){
$(this).css("border-color","#e1e1e1")
var str =$.trim($(this).val());
if(str == ""){
$(this).next("label").show();
}}
});
//提交表单
$("#myform .okbtn").click(function(){
var uname=$("#uname").val();
var tel=$("#tel").val();
var company=$("#company").val(); var chinese = /^[\u4e00-\u9fa5]{2,4}$/;
var telpattern = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
var phonepattern= /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(14[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
//return this.optional(element) || (chinese.test(value)); if(!chinese.test(uname)){
layer.msg('姓名未填写或未填写汉字!', {icon:0});
return false;
}
if(!telpattern.test(tel) && !phonepattern.test(tel)){
layer.msg('联系方式填写错误!', {icon:0});
return false;
}
if($.trim(company)==''){
layer.msg('请填写公司名称!', {icon:0});
return false;
} ajaxSubmit($("#myform"));
});
});*/
/*
$("#seller").click(function(){
layer.open({
type: 1,
title: "卖家报名",
closeBtn: true,
shadeClose: true,
area:['500px','300px'],
skin: 'sellerBox',
content:htmlStr2
});
//表单文本框提示文字
$("#myform input").on({
focus:function(){$(this).next("label").hide();},
blur:function(){
var str =$.trim($(this).val());
if(str == ""){
$(this).next("label").show();
}}
});
//提交表单
$("#myform .okbtn").click(function(){
var uname=$("#uname").val();
var tel=$("#tel").val();
var company=$("#company").val(); var chinese = /^[\u4e00-\u9fa5]{2,4}$/;
var telpattern = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
var phonepattern= /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(14[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
//return this.optional(element) || (chinese.test(value)); if(!chinese.test(uname)){
layer.msg('姓名未填写或填写错误!', {icon:0});
return false;
}
if(!telpattern.test(tel) && !phonepattern.test(tel)){
layer.msg('联系方式填写错误!', {icon:0});
return false;
}
if($.trim(company)==''){
layer.msg('请填写公司名称!', {icon:0});
return false;
}
ajaxSubmit($("#myform"));
});
});*/ //将form转为AJAX提交
function ajaxSubmit(frm) {
var dataPara = getFormJson(frm);
var url=$("#myform").attr("action"); $.ajax({
url:$("#myform").attr("action"),
type:$("#myform").attr("method"),
data: dataPara,
success: function(data){
layer.closeAll();
if(data==='1'){
console.log(1);
layer.msg('报名成功!', {icon: 1});
}else if(data==='0'){
console.log(0);
layer.msg('报名失败,请重试!', {icon: 2});
}else{
console.log(data);
layer.msg(data, {icon: 0});
}
}
});
} //将form中的值转换为键值对。
function getFormJson(frm) {
var o = {dosubmit:1};
var a = $(frm).serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
} //铝箔图片查看弹出层
function showPic(id,start,src,pid){
var json = {
"title": "铝箔相册", //相册标题
"id": id, //相册id
"start": start, //初始显示的图片序号,默认0
"data": [ //相册包含的图片,数组格式
{
"alt": "铝箔图片",
"pid": pid, //图片id
"src": "images/pic/"+src, //原图地址
"thumb": "images/pic/ProductImg2.jpg" //缩略图地址
}
]
};
layer.photos({
photos: json,
closeBtn: true,
});
};

序列化layer创建的弹出表单并ajax提交的更多相关文章

  1. jquery序列化from表单使用ajax提交返回json数据(使用struts2注解result type = json)

    1.action类引入struts2的"json-default"拦截器栈 @ParentPackage("json-default") //示例 @Paren ...

  2. layui弹出表单提交后,界面model验证部分起作用

    情况1----input属性中type=submit时验证都可以起作用,但是弹出层表单的返回值不能获取,所以用ajax二次提交后会出现重复添加数据的问题 情况2----input属性中type=but ...

  3. 织梦自定义表单通过ajax提交的实现方法

    自定义表单通过ajax判断,提交不用跳转页面,提高用户体验.具体方法如下: html表单代码部分,就提交按钮改成botton,,添加onclick事件 表单代码: <form action=&q ...

  4. ExtJs 4.2.1 点击按钮弹出表单的窗口

    初学ExtJs,做项目的时候想做一个这样的效果:点击按钮弹出对话框,之前一直是使用EasyUi来做的, EasyUi里有Dialog,用起来很方便,但是现在转移到ExtJs上后,发现没有Dialog这 ...

  5. jquery序列化form表单使用ajax提交后处理返回的json数据

    1.返回json字符串: /** 将一个字符串输出到浏览器 */ protected void writeJson(String json) { PrintWriter pw = null; try ...

  6. jquery.validate和jquery.form配合实现验证表单后AJAX提交

    基础代码其实很简单,之后一点一点扩充.最终代码写在最后. 表单: <form action="@Url.Action("AddColumns","Cont ...

  7. javascript表单的Ajax 提交插件的使用

    Ajax 提交插件 form.js 表单的下载地址:官方网站:http://malsup.com/jquery/form/ form.js 插件有两个核心方法:ajaxForm()和ajaxSubmi ...

  8. Form 表单用 Ajax 提交数据并用 jQuery Validate 验证

    表单填写需要验证可用插件 jQuery Validate 提交数据使用 Ajax 可操控性得到提到 注意:请自行引入 jQuery 和 jQuery Validate HTML 代码 <form ...

  9. Bootstrap 弹出表单

随机推荐

  1. 使用ToolRunner运行Hadoop程序基本原理分析

    为了简化命令行方式运行作业,Hadoop自带了一些辅助类.GenericOptionsParser是一个类,用来解释常用的Hadoop命令行选项,并根据需要,为Configuration对象设置相应的 ...

  2. symfony2 登录验证(转自http://www.newlifeclan.com/symfony/archives/300)

    注意:如果你需要为存储在某种数据库中的用户做一个登录表单,那么你应该考虑使用FOSUserBundle,这有助于你建立你的User对象,还为您提供了常见的登录.注册.忘记密码的路由和控制器. 在此文章 ...

  3. SpringMVC–SSH -- RESTful -- JSR303

    最近在使用SpringMVC+MyBatis感觉用起来效果很好.我不太明白SpringMVC和SSH的关系,遂搜索了一下.原来使用SpringMVC之后,可以替代之前的SSH这种开发模式. 附上知乎链 ...

  4. [LA] 3027 - Corporative Network [并查集]

    A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...

  5. Here are some of my ideas .

    1:Learning english is very important ,its the very useful for my major studying and my future develo ...

  6. 《Programming WPF》翻译 第8章 3.Storyboard

    原文:<Programming WPF>翻译 第8章 3.Storyboard Storyboard是动画的集合.如果你使用了标记,所有的动画必须要被定义在一个Storyboard中.(在 ...

  7. windows下编译firefox

    可以自己定制下.估计很简单..... 官方文档扫一遍: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_I ...

  8. Transposed Matrix

    Transposed Matrix In linear algebra, the transpose of a matrix A is another matrix AT (also written  ...

  9. UNIX时间戳与日期的相互转换

    mysql中UNIX时间戳与日期的相互转换 UNIX时间戳转换为日期用函数:FROM_UNIXTIME() select FROM_UNIXTIME(1410318106); 日期转换为UNIX时间戳 ...

  10. 归纳下js面向对象的几种常见写法

    //定义Circle类,拥有成员变量r,常量PI和计算面积的成员函数area() 1.工厂方式 var Circle = function() { var obj = new Object(); ob ...