Home > Article > Web Front-end > How does javascript trigger the clicked event of a button?
btnObj.click() is to actually use a program to click the button, triggering the onclick() event of the button. It can be called when the button is not hidden, but not after the button is hidden. Do not use it if it is hidden. Visiable attribute, use "style.display=none".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
function load(){ //下面两种方法效果是一样的 document.getElementById("target").onclick(); document.getElementById("target").click(); }
Note:
1.btnObj.click() is to actually use a program to click the button, triggering the button's onclick() event , it can be called when the button is not hidden, but not after the button is hidden. Do not use the Visiable attribute to set the hiding, use style.display=none
2.btnObj.onclick() just simply calls btnObj The method pointed to by onclick just calls the method and does not trigger the event.
$(function(){ // test 的点击事件 $("#test").click(function(){ alert("点击了"); }); // 调用 test 的点击事件的两种方法 $("#test").trigger("click"); $("#test").click() })
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How does javascript trigger the clicked event of a button?. For more information, please follow other related articles on the PHP Chinese website!