如何创建激活jQuery / js函数的图像按钮

我需要在tr元素中使用类似按钮来点击时执行js / jquery事务。

奇怪的是,我很难找到如何从内联html /图像按钮执行jquery / js的良好知识。

这就是我的想法:

首先为like按钮创建一个自定义函数

jQuery.fn.likebutn = function(theword, wordnumber) { //check if button is lighted up and if it is break //change button to lighted up jQuery(this).attr("src", "http://sofzh.miximages.com/javascript/n18g3q.png"); //add word to a div element jQuery('#cntrldiv0').append("

theword

"); //ajax like.php file with the word and username/id jQuery.post('like.php', {theword:theword, userid: userid}); };

然后在图像按钮元素中动态插入函数调用及其参数(因为表是在php中创建的)(所以在html中内联)

 likebutn({theword: ${'row' . $wordnumber}, wordnumber:$wordnumber}); 

哪个输出

likebutn(theword:foraminated,wordnumber:1)

例如。

那么如何从html中唤起这样的function呢?

在旁注中,为什么有这么多事件在jquery / js图像按钮中监听我在浏览网页时看到的(而不是我建议的),是不是比在html中引入内联慢?

以下是构造的外观: http : //jsfiddle.net/Bc64R/

除非你有一个名为foraminated的变量,否则这是不正确的:

 likebutn(theword:foraminated, wordnumber:1) 

应该:

 likebutn(theword:"foraminated", wordnumber:1) 

来自HTML:

<... onclick =“jQuery(this).likebutn(...)”>