您的位置:首页 > Web前端 > JavaScript

批量数据录入, 辅助输入数据, 以及相关检测(JScript 客户端)(原创)

2004-09-26 20:52 513 查看
批量数据录入, 辅助输入数据, 以及相关检测(JScript 客户端)(原创)
作者: 萧月痕
相关链接:批量数据录入, 辅助输入数据, 以及相关检测(ASP 服务器端)(原创)
<script language="JScript">
<!--
//回车代替TAB, 当遇到按钮时, 则执行按钮动作
function keyDown()
{
if(event.keyCode == 13)
{
//检测样式名, 确实是否为按钮
if(event.srcElement.className == "fbtclass") return true;
event.keyCode = 9;
return true;
}
}
document.onkeydown = keyDown;

var myform;
//批量记录总数, 便于检测用户输入
var intTotal = <%= intBillTotal%>;
//初始化网页表单项目
function init(form)
{
myform = form;
formsum();
}

//用IE网页对话框(模式)辅助输入数据
function openWin(intID)
{
var arrValue = window.showModalDialog("<%= GBL__STR_SYS_ROOT_PATH%>WInfo/Product_wList.asp?at=1&1");
if ((arrValue != null) && (arrValue.length == 6))
{
var id = isNaN(parseInt(arrValue[0])) ? 0 : parseInt(arrValue[0]);
if (id == 0) return;

//一项产品只能输一行
for(var i = 1; i <= intTotal; i++)
{
if ((isNaN(parseInt(myform["fih_pid_" + i].value)) ? 0 : parseInt(myform["fih_pid_" + i].value)) == id)
{
alert("已输入此项产品数据, 若需更改数据, 请在表单中直接修改!");
return;
}
}

try
{
myform["fih_pid_" + intID].value = arrValue[0];
myform["fih_pmodel_" + intID].value = arrValue[1];
myform["fih_pvalue_" + intID].value = arrValue[2];
myform["fih_pspec_" + intID].value = arrValue[3];
myform["fih_punit_" + intID].value = arrValue[4];
myform["fih_pprice_" + intID].value = filternum(arrValue[5], 2);
myform["fih_ptotal_" + intID].value = "0.00";
myform["fih_pcost_" + intID].value = "0.00";
}
catch(e)
{
alert("表单填充出错!");
}
}else
{
clearrow(intID)
}
}

function enterDown()
{
if(event.keyCode == 13) return((event.srcElement.tagName == "TEXTAREA") ? true : false);
}

//重置表单
function formreset(form)
{
var flag = confirm("确实要撤消所有操作并返回初始值吗?");
if (flag){
form.reset();
}
}

//提交表单
function formsubmit(form)
{
if (formsubmitcheck() && confirm("确定提交数据吗?")){
form.submit();
}
}

//检测数据
function formsubmitcheck()
{
var flag = false;
var id = 0;
for(var i = 1; i <= intTotal; i++)
{
id = isNaN(parseInt(myform["fih_pid_" + i].value)) ? 0 : parseInt(myform["fih_pid_" + i].value);
if (id > 0)
{
flag = true;
break;
}
}
if (!flag) alert("空数据不能提交!");
return flag;
}

//合计
function formsum()
{
var totalSum = 0;
for(var i = 1; i <= intTotal; i++)
{
if (isNaN(parseInt(myform["fih_pid_" + i].value)) ? 0 : parseInt(myform["fih_pid_" + i].value) == 0) continue;
totalSum += isNaN(parseFloat(myform["fih_pcost_" + i].value)) ? 0 : parseFloat(myform["fih_pcost_" + i].value);
}
myform.fit_totalprice.value = filternum(totalSum, 2);
window.setTimeout( "formsum()", 200);
}

//计算行金额总数
function sumrow(id)
{
var intID = isNaN(parseInt(myform["fih_pid_" + id].value)) ? 0 : parseInt(myform["fih_pid_" + id].value);
if (intID <= 0)
{
clearrow(id)
return;
}
var num   = filternum(myform["fih_ptotal_" + id].value, 2);
var price  = filternum(myform["fih_pprice_" + id].value, 2);
if (price < 0)
{
alert("单价不能为负数!");
price = Math.abs(price);
myform["fih_pprice_" + id].value = price;
}
var spec   = eval(myform["fih_pspec_" + id].value);
var spec   = isNaN(parseFloat(spec)) ? 1 : filternum(spec, 2);
var cost   = num * price * spec;

myform["fih_ptotal_" + id].value = num;
myform["fih_pprice_" + id].value = price;
myform["fih_pcost_" + id].value = filternum(cost, 2);
}

//清空某行数据
function clearrow(id)
{
myform["fih_pid_" + id].value = 0;
myform["fih_pmodel_" + id].value = "";
myform["fih_pvalue_" + id].value = "";
myform["fih_pspec_" + id].value = "";
myform["fih_punit_" + id].value = "";
myform["fih_pprice_" + id].value = "";
myform["fih_ptotal_" + id].value = "";
myform["fih_pcost_" + id].value = "";
}

//格式化数字
function filternum(num, k)
{
var num   = isNaN(parseFloat(num)) ? 0 : parseFloat(num);
try{
return num.toFixed(k);
}
catch(e) {
alert("脚本引擎不支持此操作, 请升级您的浏览为IE5.5以上!");
return 0;
}
}

//检测VBS日期格式
function isVbDate(str)
{
//最小年份
var miny = 2000;
//最大年份
var maxy = 2005;
var reg = /^(/d{4})(-|//|/.)(/d{1,2})/2(/d{1,2})$/;
result = str.match(reg);
if(result == null) return false;
var y, m, d;
//获得用户输入之年份
y = result[1];
//获得用户输入之月份
m = parseInt(result[3]);
//获得用户输入之日
d = parseInt(result[4]);
if ((y > maxy) || (y < miny))
{
alert("年份不能超出( " + miny + " - " + maxy + " )范围!");
return false;
}
if ((m < 1) || (m > 12) || (d < 1) || (d > 31)) return false;
if (((m == 4) || (m == 6) || (m == 9) || (m == 11)) && (d > 30)) return false;
if((y % 4) == 0)
{
if ((m == 2) && (d > 29)) return false;
}else
{
if ((m == 2) && (d > 28)) return false;
}
return true;
}

//检测VBS日期格式
function checkVbDate(input)
{
if (input.value == "") return;
if (!isVbDate(input.value))
{
alert("日期格式不正确, 请重新输入");
input.focus();
input.select();
}
}

//用IE网页对话框(模式)辅助输入客户数据
function BrowseCostmer()
{
var arrValue = window.showModalDialog("<%= GBL__STR_SYS_ROOT_PATH%>WInfo/Costmer_wList.asp");
if ((arrValue != null) && (arrValue.length == 2))
{
var id = isNaN(parseInt(arrValue[0])) ? 0 : parseInt(arrValue[0]);
var Costmer = arrValue[1];

myform.fit_CustID.value = id;
myform.fit_CustName.value = Costmer;
}
}

//-->
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐