1.dialog组件的使用
类似Bootstrap中的模态框
<div id="dd" style = "display:none"></div>
$('#dd').dialog({
title: '新增图书',
width: 400,
height: 250,
closed: false,
cache: false,
href: xPath+'/editBook.jsp',//新增的表单页面
modal: true,
buttons:[{
text:'保存',
handler:function(){
//ajax方法传递数据到servlet中
$.post("add路径",$("表单id").serialize(),function(data){
if(data.success){
$.messager.alert('我的消息','这是一个提示信息!');
}
});
}
},{
text:'关闭',
handler:function(){...}
}]
});
2.$("表单id").serialize()
jQuery中提供的一个方法,可以直接不需要手动获取输入框值,直接打包形成一个url参数拼接。
3.消息框的使用
$.message.alert();
4.
$('#dd').dialog({
title: '新增图书',
width: 400,
height: 260,
closed: false,
cache: false,
href: xPath+'/addBook.jsp',
modal: true ,
buttons:[{
text:'新增',
handler:function(){
$.ajax({
url:xPath+"/addBook",
type:"post",
data:$('#bookForm').serialize(),//获取表单中的值
datatype:"text",
success:function(data){
let flag=data.message;
if(flag){
$.messager.alert('我的消息','新增成功!');
myload();//刷新界面,
$('#dd').dialog('close');//关闭界面
}
}
});
}
},{
text:'关闭',
handler:function(){
$('#dd').dialog('close');
}
}]
});
以上代码弹出对话框窗口
url属性引入表单,代码如下
<div>
<form id="bookForm">
<input type="hidden" name="bid" id="bid"/>
<div style="margin: 15px;">
<label for="name">书名:</label>
<input id = "bookname" class="easyui-textbox" name="bname" style="width:300px" data-options="required:true">
</div>
<div style="margin: 15px;">
<label for="price">价格:</label>
<input class="easyui-textbox" name="bprice" style="width:300px" data-options="required:true">
</div>
<div style="margin: 15px;">
<label for="booktype">类型:</label>
<input class="easyui-textbox" name="btype" style="width:300px" data-options="required:true">
</div>
</form>
</div>
这篇博客介绍了如何利用jQuery的dialog组件创建模态框,并结合Ajax进行表单数据的提交和处理。示例中展示了新增图书的对话框,表单数据通过serialize()方法打包,然后通过Ajax发送到后台Servlet,成功后使用$.messager.alert显示提示信息。此外,还展示了对话框的关闭功能。
1万+

被折叠的 条评论
为什么被折叠?



