admin管理员组

文章数量:1297011

Can anybody help me out writing this on onClick event on href tag?

 string x= "<a href=\"JavaScript:callfunction(event,'"+ y.id.tostring() + "');\">click</a>";

Can anybody help me out writing this on onClick event on href tag?

 string x= "<a href=\"JavaScript:callfunction(event,'"+ y.id.tostring() + "');\">click</a>";
Share Improve this question edited May 31, 2012 at 15:41 Michael Berry 72.4k23 gold badges163 silver badges224 bronze badges asked May 31, 2012 at 15:27 user957178user957178 6314 gold badges16 silver badges27 bronze badges 1
  • 6 What are you trying to do? What is it doing? What is your question? – gcochard Commented May 31, 2012 at 15:29
Add a ment  | 

3 Answers 3

Reset to default 6
string x = string.Format(
    "<a href=\"#\" onclick=\"callfunction(event, '{0}')\">click</a>", 
    y.id
);

why not something like :

string x= "<a href=\"#\" onclick=\"callfunction(event,'"+ y.id.tostring() + "');\">click</a>";

Just an alternative way using DOM responsible methods for this kind of task

var x     = document.createElement('a');
x.href    = "#";
x.onclick = function(evt) {
   callfunction(evt, y.id.tostring())
}

<destination-node>.appendChild(x);

本文标签: javascripthow to write onclick event for href tagStack Overflow