开发者

Dynamically change an onclick event to a new function

开发者 https://www.devze.com 2023-01-15 19:11 出处:网络
How do I dynamically change an onclick event to a new function? Here is the example: <img name="space1" id="space1" src="images/80开发者_JS百科01.jpg" height="150

How do I dynamically change an onclick event to a new function? Here is the example:

<img name="space1" id="space1" src="images/80开发者_JS百科01.jpg" height="150 px" onclick="lrgWithInfo('1')" />

Here is what isn't working. All I want to change is the value passed.

document.getElementById("space1").onclick = lrgWithInfo('13');


document.getElementById("space1").onclick = lrgWithInfo('13');

This assigns the output of lrgWithInfo('13'); to you on click function. You could try

document.getElementById("space1").onclick = function () { lrgWithInfo('13'); };


Thank-you so very much for your help!!

It worked, and although I tried using a new function I may not have added the semi colan inside the brackets. I never would have noticed that on my own.

Thanks again, project worked, and I will be back with a million more questions.

You rock!

kim

0

精彩评论

暂无评论...
验证码 换一张
取 消