attachEvent带参数问题,帮忙看看吧!

梅雪香 2006-01-14 10:53:00
我需要在cascadeListBox.prototype.addEvent函数里为列表框动态添加事件,要添加的事件为cascadeListBox.prototype.dltChg ,带一个参数index
本来用function(){}的方式来写的,可以有问题,在cascadeListBox.prototype.dltChg中根本访问不到cascadeListBox里的this.dlts对象了.如何解决?大侠救我!
附代码如下:

<html>
<head>
<script language="JavaScript">
<!--
function cascadeListBox(){
//this.isShowPlease = true; //是否显示请选择**字样
this.id = "lb";
this.dlts = arguments; //取得参数列表,形式如: ("dlt1","dlt2","dlt3"[,"dlt4"])参数个数不限
this.arrText = new Array();
this.arrText[0] = "#:1:text0-#-1;#:2:text0-#-2;#:3:text0-#-3";
this.arrText[1] = "1:1:text1-1-1;1:2:text1-1-2;2:3:text1-2-3;2:4:text1-2-4;3:5:text1-3-5;3:6:text1-3-6";
this.arrText[2] = "1:1:text1-1-1;1:2:text1-1-2;2:3:text1-2-3;2:4:text1-2-4;3:5:text1-3-5;3:6:text1-3-6";
this.toString = function(){
//根据输入参数,取得列表框对象集合
var pArr = this.dlts;
//alert(pArr.length);
if (pArr.length == 1)
this.dlts = document.getElementsByName(pArr[0]);
else
for(var i=0,j=pArr.length;i<j;i++)
this.dlts[i]=document.getElementById(pArr[i]);
//alert(this.dlts);

for(var i=0,j=this.dlts.length;i<j;i++)
if(this.dlts[i] == null)
throw new error(-1,"参数输入有误!/n无法根据参数取得列表框对象!");

//初始化列表框数据
this.initData();
this.setStyle();
this.attachEventForDlts();
}
}
cascadeListBox.prototype.dltChg = function(index){
var pId = this.dlts[index].value;
//alert(this.dlts[index].outerHTML);
this.addOptions(++i,pId);
this.dltChg(i);
}

cascadeListBox.prototype.attachEventForDlts = function(){
for(var i=0,j=this.dlts.length-1;i<j;i++)
this.addEvent(i);
}

cascadeListBox.prototype.addEvent = function(index){
this.dlts[index].attachEvent("onchange",eval(this.dltChg(index)));
}

cascadeListBox.prototype.setStyle = function(){
//set the style of dropdownlist at here
}

cascadeListBox.prototype.initData = function(){
this.addOptions(0,"#");
this.dlts[0].selectedIndex = -1;
}

cascadeListBox.prototype.addOptions = function(index,parentId){
var dlt = this.dlts[index];
dlt.innerHTML="";
var str = this.arrText[index];
var reg = new RegExp("\s*"+parentId+"\s*:\s*[^:^;]*\s*:\s*[^:^;]*\s*(?=;|$)","g");
var txts = str.match(reg);
for(var i=0,j=txts.length;i<j;i++){
var attrs = txts[i].split(":");
var opt = document.createElement("OPTION");
opt.setAttribute("parentId",attrs[0]);
opt.setAttribute("value",attrs[1]);
opt.setAttribute("text",attrs[2]);
dlt.options.add(opt);
}
}

//-->
</script>
</head>
<body>
<select name="dlt"></select>
<select name="dlt"></select>
<select name="dlt"></select>
<script language="JavaScript">
<!--
(new cascadeListBox("dlt")).toString();
//-->
</script>
</body>
</html>
...全文
369 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ice_berg16 2006-01-14
  • 打赏
  • 举报
回复
cascadeListBox.prototype.addEvent = function(index){
var self =this;
this.dlts[index].attachEvent("onchange",function(){
self.dltChg(index);
});
}
它通过读取 Excel 表格中的业务数据,结合 Word 模板,自动生成多个独立的合同文件,并自动处理了表格中“合计”行的合并与中文大写金额转换。 资源名称:合同文档自动化生成脚本 (1.py) 名字真是乱起 核心功能:Excel 数据读取 → Word 模板渲染 → 表格单元格合并与金额处理 → 批量导出 Word 文档。 适用场景:财务、销售或行政部门需要根据订单或业务明细,批量制作格式统一的合同、报价单或结算单。 1. 自动把“钱”变成“大写” 它干了啥:它内置了一个翻译功能,专门把阿拉伯数字(比如 100.50)自动转换成财务专用的中文大写(比如 壹佰元伍角)。 为什么有用:写合同最怕手滑写错金额,或者大写格式不对。这个功能全自动搞定,既标准又不会出错。 2. 自动“装修”表格底部 它干了啥:生成文档后,它会自动找到表格的最后一行,把前几列合并成一个大格子,写上“合计:XXX(大写金额)”,并在最右边填上具体的数字总额。 为什么有用:平时我们做完表格,还得手动去合并单元格、算总数、填大写,非常繁琐。这个脚本直接一步到位,把表格收尾工作做得漂漂亮亮。 3. 像“发传单”一样批量做合同 它干了啥:它会看你的 Excel 表格,按照“编号”把数据归类。 如果是同一个编号的货物,它会把它们塞进同一个合同里(比如一个客户买了三样东西,会自动列三行)。 如果是不同的编号,它就生成不同的合同文件。 为什么有用:不管你有一百个还是一千个订单,它都能自动拆分,给每个客户生成一份独立的、内容准确的合同,完全不用人工去复制粘贴。

87,988

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧