问题描述
自动生成控件,帮定事件,回车的时候第一次好用,第二次就不好使_count=document.createElement("input");_count.id="count"+(MainDataListBox.rows.length-3).toString();_count.type="text";_count.style.border=0;_count.style.width=50;_count.attachEvent("onkeydown",function(){ShowCountOrderByAdd(_count)});_count.attachEvent("onblur",function(){ShowCountOrderNoEnter(_count)});functionShowCountOrderByAdd(id)//第一次的时候count控件能传入,第二次就传入我在input中录入的值{if(event.keyCode==13){varstr=id.id.substring(5,id.id.length);//第二次因为没有id,只是输入的数字,就会报错var_cou=0;table=document.getElementById("MainDataListBox");count=document.getElementById("count"+(num-1).toString());price=document.getElementById("price"+(num-1).toString());。。。。。。。。}
解决方案
解决方案二:
用个static变量来判断第一次,第二次……再来取相应的str值
解决方案三:
第一次传值后记录一下id,第二次让他有id就可以了!
解决方案四:
不知你是怎么操作的,是不是onblur的问题
解决方案五:
可以用_count.attachEvent("onkeydown",function(){ShowCountOrderByAdd()});functionShowCountOrderByAdd(){if(event.keyCode==13){varid=event.srcElement;
解决方案六:
引用2楼maco_wang的回复:
第一次传值后记录一下id,第二次让他有id就可以了!
解决方案七:
大概是少个onFocus的吧..我记得遇到过这样的问题.
解决方案八:
id命名为“字符”+生成数量
解决方案九:
id.id....太晦涩的代码,说明你的意图
解决方案十:
尽量不要用全局变量,而应该传参的形式
解决方案十一:
友情up