How do I add an onclick
event to a tag in HTML programmatically?
I want to be able to click a link, and have an onclick
event attached to a Javascript function take effect on another tag.
Here is what I have so far:
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.id="List["+num+"].id";
element1.name="List["+num+"].id";
element1.onclick="javascript:CalCal()";
cell1.appendChild(element1);
I want to call a Javascript function CalCal()
on onClick
event. Is this possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…