Jquery表onclick事件

时间:2012-02-09 14:33:23

标签: php jquery html

我在jquery中有一个函数,它转到一个php文件,查询数据库会在一个表中返回结果,每行都有一个按钮, 如何访问jquery所在页面中的按钮。这是一些代码

//function to get table form php file with button on each row
function show(str)
{

$.post('INCLUDES/gettable.php',{club: str},
    function(output)
    {

        $('#box').html(output).show();
    });

}
 //when button from table is clicked do something
   $("button").click(function()
  {
      alert("hello");
   }

感谢任何帮助

2 个答案:

答案 0 :(得分:1)

使用live()或更好on()(随jQuery的最新版本提供)动态生成的html /数据:

$("button").on('click', function()
{
  alert("hello");
}

或者

$("button").live('click', function()
{
  alert("hello");
}

答案 1 :(得分:0)

看起来您正在动态加载表行,因此它们不会在页面加载时成为dom的一部分。

您应该使用.on()函数来访问这些内容 - 请参阅jQuery API docs

相关问题