JS代码
//新建notice对话框
$("#new_notice_dialog").dialog({
autoOpen: false,//控制对话框的显示与隐藏
height: 520,
width: 1200,
minHeight:300,
minWidth:600,
modal: true,
buttons:[
{
text:"保存",
click:function(){
//验证
var title=$("#new_notice_title").val();
var createDate = $("#new_notice_date").val();
var validDays = $("#new_notice_validDays").val();
var myEditor = CKEDITOR.instances.editor1;
var content = myEditor.getData();
// alert("新建公告时,获取的公告内容为:"+content);
// var content = $("#new_notice_content").val();
//验证一个数是否是正整数
var regInteger=/^([1-9]\d*)$/;
if(title == null || $.trim(title) == ""){
alert("请输入公告标题!");
return;
}else if(title.length > 50){
alert("公告标题不能超过50个字符!");
return;
}else if(createDate == null || $.trim(createDate) == ""){
alert("请输入公告发布时间!");
return;
}else if(validDays == null || $.trim(validDays) == ""){
alert("请输入公告有效期!");
return;
}
else if(!regInteger.test(validDays)){
alert("公告有效期只能输入正整数!");
return;
}
else if(content == null || $.trim(content) == ""){
alert("请输入公告内容!");
return ;
}
// else if(content.indexOf("
// alert("请不要插入图片!");
// return;
// }
//保存notice
$("#new_notice_form").submit();
// $(this).parent.location.reload();
}
},
{
text:"取消",
click:function(){
$("#new_notice_title").val("");
$("#new_notice_validDays").val("1");
// $("#new_notice_content").val("");
var myEditor = CKEDITOR.instances.editor1;
myEditor.setData("");
$(this).dialog("close");
}
}
]
});
//编辑notice对话框
$("#edit_notice_dialog").dialog({
autoOpen: false,
height: 530,
width: 1200,
minHeight:300,
minWidth:600,
modal: true,
buttons:[
{
text:"保存",
click:function(){
//验证
var id=$("#edit_notice_id").val();
var title=$("#edit_notice_title").val();
var date = $("#edit_notice_date").val();
var validDays = $("#edit_notice_validDays").val();
// var content = $("#edit_notice_content").val();
var myEditor = CKEDITOR.instances.editor2;
var content = myEditor.getData();
var visiable = 0;
var visiable_span_class;
//验证一个数是否是整数,编辑阶段允许为0(公告设置失效)
var regInteger=/^(0|[1-9]\d*)$/;
if($("#visiable_true").attr("checked") == true){
visiable = 0;
visiable_span_class = "icon_true";
}
if($("#visiable_false").attr("checked") == true){
visiable = 1;
visiable_span_class = "icon_false";
}
if(title == null || $.trim(title) == ""){
alert("请输入公告标题!");
return;
}else if(title.length > 50){
alert("公告标题不能超过50个字符!");
return;
}else if(date == null || $.trim(date) == ""){
alert("公告发布时间不能为空!");
return;
}else if(validDays == null || $.trim(validDays) == ""){
alert("公告有效期不能为空!");
return;
}else if(!regInteger.test(validDays)){
alert("公告有效期只能输入整数!");
return;
}else if(content == null || $.trim(content) == ""){
alert("请输入公告内容!");
return ;
}
$("#edit_notice_form").submit();
//清空对话框内容
$("#edit_notice_id").val("");
$("#edit_notice_title").val("");
$("#edit_notice_date").val("");
$("#edit_notice_content").val("");
var myEditor = CKEDITOR.instances.editor2;
myEditor.setData("");
$("#visiable_false").removeAttr("checked");
$("#visiable_true").removeAttr("checked");
$(this).parent.location.reload(); 在这个地方刷新,它会刷新当前这个弹出框
$(this).dialog("close");
}
},
{
text:"取消",
click:function(){
$("#edit_notice_id").val("");
$("#edit_notice_title").val("");
$("#edit_notice_date").val("");
$("#edit_notice_validDays").val("");
// $("#edit_notice_content").val("");
var myEditor = CKEDITOR.instances.editor2;
myEditor.setData("");
$("#visiable_false").removeAttr("checked");
$("#visiable_true").removeAttr("checked");
$(this).dialog("close");
}
}
]
});
$("#add").click(function(){
$("#new_notice_dialog").dialog("open");
});
});