如何动态替换表单对象的onClick事件
代码如下:
<script language= "javascript ">
<!--
function scadd(v,pid)
{
var a=document.all.buyimg;
//a.onclick=aa(pid,v);
a.onclick=function(){return "return Addcat(123,1, 'test '); ";}
}
function aa(a,b)
{
return Addcat(a,1, '备注: '+b);
}
function Addcat(id,num,memo)
{
alert(id+ ", "+num+ ", "+memo);
}
-->
</script>
<select size=1 class= "input1 " onChange= "scadd(this.value,23) ">
<option value= "无 " selected> 选择 </option>
<option value= "1# "> 1# </option>
<option value= "2# "> 2# </option>
<option value= "3# "> 3# </option>
</select>
<br>
<img src= "images/buy.gif " id= "buyimg " onClick= "return Addcat(23,1, '无 '); " style= "cursor:hand; " width= "89 " height= "36 ">
不知道为何替换onClick事件后,onClick无法响应。是我代码有问题吗?请高手赐教,不甚感激!!!
------解决方案--------------------scadd这里面return 部分的问题,改成这样
function scadd(v,pid)
{
var a=document.all.buyimg;
//a.onclick=aa(pid,v);
alert(a.onclick);
a.onclick=function(){return Addcat(123,1, 'test ');};
}