对于一些常用的按钮的样色设计和用户交互设计
先看看效果:
这里涉及好几个页面,因为太琐碎了,所以只提供核心的脚本
//
JavaScript Document
// ==============================================================================
/* 通用控制页脚本
建档时间:2007-7-2
最后修改时间:2007-7-3
作者:陈满森
说明:
1.此脚本支持新增单条记录、编辑单条记录、删除单条或多条记录
2.函数与页面的对应关系:
Controler()为操作页按钮(_controler.jsp)要调用的函数
combineBh()为列表页checkbox(message_list.jsp)要调用的函数
CopyForm()为表单页(message_manage.jsp)要调用的函数
3.内部函数的作用:
ShowEditForm()用于在新增和修改的时候显示表单
EditForm()用于判断用户的动作
SubmitForm()用于提交表单,带简单过滤
*/// ==============================================================================
function Controler(action,type,targetDivID,ajaxDataUrl){
if ($(targetDivID).innerHTML == "" ){
EditForm(action,type,targetDivID,ajaxDataUrl);
} else {
if (confirm( " 是否放弃当前操作? " )){
$(targetDivID).innerHTML = "" ;
}
}
}
function CopyForm(){
var ObjAction = $( " form_action " );
var ObjBh = $( " bh " );
var ObjZt = $( " zt " );
var ObjDxlx = $( " dxlx " );
var ObjNr = $( " nr " );
var ObjXxlx = $( " xxlx " );
ObjAction.value = $F( " tempAction " );
ObjBh.value = $F( " tempBh " );
ObjZt.value = $F( " tempZt " );
select_setselected(ObjDxlx,$F( " tempDxlx " ))
ObjNr.value = $F( " tempNr " );
ObjXxlx.value = $F( " tempXxlx " );
}
function ShowEditForm(type,targetID,url){
var pars = "" ;
pars = ajaxaddpars_var( " xxlx " ,pars,type);
mynormalAjax(url,pars,targetID);
return false ;
}
function EditForm(action,type,targetDivID,ajaxDataUrl){
var valueBh = $F( " tempBh " );
$( " tempAction " ).value = action;
if (valueBh == "" ){
if ( " insert " == action){
ShowEditForm(type,targetDivID,ajaxDataUrl);
} else {
alert( " 请选择至少一个对象! " );
}
} else {
if ( " save " == action){
if (valueBh.indexOf( " , " ) !=- 1 ){
alert( " 只能选择一个对象进行操作! " );
} else {
ShowEditForm(type,targetDivID,ajaxDataUrl);
}
} else if ( " delete " == action){
// 因为删除不需要显示编辑表单,因此用Ajax_noreturn_div
if (confirm( " 是否真的要删除该记录? " )){
targetDivID = " Ajax_noreturn_div " ;
var pars = "" ;
pars = ajaxaddpars_formtext( " bhDelete " ,pars, " tempBh " );
pars = ajaxaddpars_formtext( " doDelete " ,pars, " tempAction " );
mynormalAjax(ajaxDataUrl,pars,targetDivID);
}
} else if ( " insert " == action){
$( " tempAction " ).value = action;
$( " tempBh " ).value = "" ;
$( " tempZt " ).value = "" ;
$( " tempDxlx " ).value = " 0 " ;
$( " tempNr " ).value = "" ;
ShowEditForm(type,targetDivID,ajaxDataUrl);
}
}
}
function SubmitForm(formID){
// 提交表单
if ($F( " zt " ) == "" ) alert( " 请填写主题! " );
if ($F( " dxlx " ) == "" ) alert( " 请选择发送的对象! " );
if ($F( " nr " ) == "" ) alert( " 请填写内容! " );
if ($F( " zt " ) != "" && $F( " dxlx " ) != "" && $F( " nr " ) != "" ) $(formID).submit();
}
// ==============================================================================
/* 通用列表选择脚本
建档时间:2007-7-2
最后修改时间:2007-7-2
作者:陈满森
说明:
1.此脚本将动态记录用户选中的对象
2.target----最终要提交编号的ID,currentBh----当前记录的ID前缀,
checkedBh----选中的记录的编号
3.将选中的记录的编号用“,”组合成新的字符串
*/// ==============================================================================
function combineBh(target,checkedBh){
var temp_xl = $F(target);
var checkbox_obj = $( " currentBh_ " + checkedBh);
if (checkbox_obj.checked && temp_xl.indexOf(checkedBh) < 0 ){
if (temp_xl == "" ){
$(target).value = checkedBh;
} else {
$(target).value = temp_xl + " , " + checkedBh;
}
} else if (checkbox_obj.checked == false && temp_xl.indexOf(checkedBh) >= 0 ){
temp_xl = temp_xl.replace( new RegExp( " , " + checkedBh), "" );
temp_xl = temp_xl.replace( new RegExp(checkedBh + " , " ), "" );
temp_xl = temp_xl.replace( new RegExp(checkedBh), "" );
$(target).value = temp_xl;
}
$( " tempZt " ).value = $F( " currentZt_ " + checkedBh);
$( " tempDxlx " ).value = $F( " currentDxlx_ " + checkedBh);
$( " tempNr " ).value = $F( " currentNr_ " + checkedBh);
}
// ==============================================================================
/* 通用控制页脚本
建档时间:2007-7-2
最后修改时间:2007-7-3
作者:陈满森
说明:
1.此脚本支持新增单条记录、编辑单条记录、删除单条或多条记录
2.函数与页面的对应关系:
Controler()为操作页按钮(_controler.jsp)要调用的函数
combineBh()为列表页checkbox(message_list.jsp)要调用的函数
CopyForm()为表单页(message_manage.jsp)要调用的函数
3.内部函数的作用:
ShowEditForm()用于在新增和修改的时候显示表单
EditForm()用于判断用户的动作
SubmitForm()用于提交表单,带简单过滤
*/// ==============================================================================
function Controler(action,type,targetDivID,ajaxDataUrl){
if ($(targetDivID).innerHTML == "" ){
EditForm(action,type,targetDivID,ajaxDataUrl);
} else {
if (confirm( " 是否放弃当前操作? " )){
$(targetDivID).innerHTML = "" ;
}
}
}
function CopyForm(){
var ObjAction = $( " form_action " );
var ObjBh = $( " bh " );
var ObjZt = $( " zt " );
var ObjDxlx = $( " dxlx " );
var ObjNr = $( " nr " );
var ObjXxlx = $( " xxlx " );
ObjAction.value = $F( " tempAction " );
ObjBh.value = $F( " tempBh " );
ObjZt.value = $F( " tempZt " );
select_setselected(ObjDxlx,$F( " tempDxlx " ))
ObjNr.value = $F( " tempNr " );
ObjXxlx.value = $F( " tempXxlx " );
}
function ShowEditForm(type,targetID,url){
var pars = "" ;
pars = ajaxaddpars_var( " xxlx " ,pars,type);
mynormalAjax(url,pars,targetID);
return false ;
}
function EditForm(action,type,targetDivID,ajaxDataUrl){
var valueBh = $F( " tempBh " );
$( " tempAction " ).value = action;
if (valueBh == "" ){
if ( " insert " == action){
ShowEditForm(type,targetDivID,ajaxDataUrl);
} else {
alert( " 请选择至少一个对象! " );
}
} else {
if ( " save " == action){
if (valueBh.indexOf( " , " ) !=- 1 ){
alert( " 只能选择一个对象进行操作! " );
} else {
ShowEditForm(type,targetDivID,ajaxDataUrl);
}
} else if ( " delete " == action){
// 因为删除不需要显示编辑表单,因此用Ajax_noreturn_div
if (confirm( " 是否真的要删除该记录? " )){
targetDivID = " Ajax_noreturn_div " ;
var pars = "" ;
pars = ajaxaddpars_formtext( " bhDelete " ,pars, " tempBh " );
pars = ajaxaddpars_formtext( " doDelete " ,pars, " tempAction " );
mynormalAjax(ajaxDataUrl,pars,targetDivID);
}
} else if ( " insert " == action){
$( " tempAction " ).value = action;
$( " tempBh " ).value = "" ;
$( " tempZt " ).value = "" ;
$( " tempDxlx " ).value = " 0 " ;
$( " tempNr " ).value = "" ;
ShowEditForm(type,targetDivID,ajaxDataUrl);
}
}
}
function SubmitForm(formID){
// 提交表单
if ($F( " zt " ) == "" ) alert( " 请填写主题! " );
if ($F( " dxlx " ) == "" ) alert( " 请选择发送的对象! " );
if ($F( " nr " ) == "" ) alert( " 请填写内容! " );
if ($F( " zt " ) != "" && $F( " dxlx " ) != "" && $F( " nr " ) != "" ) $(formID).submit();
}
// ==============================================================================
/* 通用列表选择脚本
建档时间:2007-7-2
最后修改时间:2007-7-2
作者:陈满森
说明:
1.此脚本将动态记录用户选中的对象
2.target----最终要提交编号的ID,currentBh----当前记录的ID前缀,
checkedBh----选中的记录的编号
3.将选中的记录的编号用“,”组合成新的字符串
*/// ==============================================================================
function combineBh(target,checkedBh){
var temp_xl = $F(target);
var checkbox_obj = $( " currentBh_ " + checkedBh);
if (checkbox_obj.checked && temp_xl.indexOf(checkedBh) < 0 ){
if (temp_xl == "" ){
$(target).value = checkedBh;
} else {
$(target).value = temp_xl + " , " + checkedBh;
}
} else if (checkbox_obj.checked == false && temp_xl.indexOf(checkedBh) >= 0 ){
temp_xl = temp_xl.replace( new RegExp( " , " + checkedBh), "" );
temp_xl = temp_xl.replace( new RegExp(checkedBh + " , " ), "" );
temp_xl = temp_xl.replace( new RegExp(checkedBh), "" );
$(target).value = temp_xl;
}
$( " tempZt " ).value = $F( " currentZt_ " + checkedBh);
$( " tempDxlx " ).value = $F( " currentDxlx_ " + checkedBh);
$( " tempNr " ).value = $F( " currentNr_ " + checkedBh);
}