$("#mylink")<0>.click();The jQuery .click() will điện thoại tư vấn event handlers that you"ve bound but not cause the mặc định click behaviour.
Bạn đang xem: Jquery trigger click event code example
You need lớn trigger the default cliông xã method, not the one by jQuery. This can be done by adding the default clichồng option within a click event of jQuery using this.
$(function() $("a").click(function() // "this" is not a jQuery object, so it will use // the mặc định click() function this.click(); ).click(););To see a live example (opening about.com), see: http://jsfiddle.net/8H9UX/
$("#mylink").click();If your scripts are in the head then you need to ensure that the element exists, so the script should be executed when document is ready.
$(document).ready(function () $("#mylink").click(););
If you are expecting the tệp tin lớn get downloaded, it will not happen becauer trigger() will not trigger the default event.
You need to lớn wait until the DOM has finished loading. This can be done with jQuery. The anonymous function is run at page load once all the elements are available in the DOM.
use the following way.... since you want lớn tải về the file prsự kiện the link from navigating.
$(document).ready(function() $("#mylink").click(function(e) e.preventDefault(); //stop the browser navigating window.location.href = "thử nghiệm.zip"; ););
document.getElementById("mylink").click();trigger("click") will fire the click event but not the mặc định one.
$("a").click(function() alert("triggered") ) // this will be fired by trigger
your above code will not work because you have sầu assigned value in href and then you want some operation onclick of this anchor tag.
testfirst of all you have sầu assigned .zip khổng lồ href. So it will open zip file oncliông xã first and will not trigger any other operation in oncliông chồng trigger.
so whatever operation you want to lớn vì chưng , perform it first then open .zip
use code like below
test$("#mylink").click(function() // vị your operation here // now open zip );
Thanks for contributing an answer lớn Staông xã Overflow!
But avoid …Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; baông xã them up with references or personal experience.
To learn more, see our tips on writing great answers.
Post Your Answer Disthẻ
site thiết kế / hình ảnh © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.8.40160