添加事件处理程序 [英] adding an event handler
本文介绍了添加事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在应用程序中动态生成一个表,具体取决于数据库中存在的记录。我遇到的问题是当我尝试为每条记录分配一个事件处理程序时。我在每行的末尾都包含一个图像,点击后应该运行一个函数。继承我的代码,但onClick不起作用。
I am dynamically generating a table in my application depending on what records exist in the database. The problem I am having is when I try to assign an event handler to each record. I am including an image at the end o each row that when clicked should run a function. Heres my code but the onClick doesn''t work.
展开 | 选择 | Wrap | 行号
推荐答案
Just在cellview.appendChild(view)之后尝试这段代码;只需插入一行
[HTML]视图图标
var cellview = row.insertCell(3);
var view = document.createElement(" img");
view.src =" view.gif";
view.onClick = function(){go();}
view.alt =" View";
cellview.appendChild(view);
cellview.innerHTML = cellview.innerHTML
[/ HTML]
希望它能运作。如有任何疑问,请将其发回论坛
问候
Ramanan Kalirajan
Just try this code, after the cellview.appendChild(view); just insert a line
[HTML] view icon
var cellview = row.insertCell(3);
var view = document.createElement("img");
view.src="view.gif";
view.onClick=function(){go();}
view.alt = "View";
cellview.appendChild(view);
cellview.innerHTML = cellview.innerHTML
[/HTML]
hope it will work. If any prob post back it to the forum
Regards
Ramanan Kalirajan
我已设法添加活动处理程序通过将图像附加到div并将事件处理程序添加到div。我现在面临的问题是我为每条记录分配的变量需要不同。继承我的代码
I have managed to add the event handler by appending the image to a div and adding the event handler to the div. The problem I now face is that the variable I assign needs to be different for each record. Heres my code
展开 | 选择 | Wrap | 行号
第一篇文章中的代码问题是onClick。需要onclick。 JavaScript区分大小写。哪个变量需要不同?
The problem with the code in the first post was that "onClick" needed to be "onclick". JavaScript is case-sensitive. Which variable needs to be different?
这篇关于添加事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文