jQuery无法触发工作

时间:2013-06-06 14:16:45

标签: jquery triggers

我已经设置了这个简单的例子,但对于我的生活,我无法弄清楚为什么它不起作用。

jQuery(function() {
$("#otherbutton").click(function () {
  $("#firstbutton").trigger('click');
  }) 
});

实例http://codepen.io/seraphzz/pen/mlsBf

1 个答案:

答案 0 :(得分:1)

以下应该使用.on正常工作,在jQuery 1.9.1上测试。

  

<强> Demo

$(function () {
 $('#otherbutton').on('click', function () {
  $('#firstbutton').trigger('click');
 });
 $('#firstbutton').on('click', function () {
  $(this).text('clicked!');
 });
});