我想点击一个按钮点击一个点击事件.我已经编写了下面的代码.对我有用但我想知道哪一个更好的方法.
第一种方法:
jQuery( "#responav li" ).click(function() {
jQuery( "#close-icon" ).click();
});
第二种方法:
jQuery( "#responav li" ).click(function() {
jQuery( "#close-icon" ).trigger("click");
});
最佳答案 $.trigger(‘click’)的性能更高一些,因为$.click()只运行$.trigger(‘click’).
从https://api.jquery.com/click/起
This method is a shortcut for […] .trigger( “click” )
从http://api.jquery.com/trigger/开始
Any event handlers attached with .on() or one of its shortcut methods are triggered when the corresponding event occurs. They can be fired manually, however, with the .trigger() method. A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user.