你会如何在jQuery中模拟点击?

时间:2015-05-03 22:59:51

标签: javascript jquery click

我试过.click(),显然不是这样。如何模拟点击并使网页功能就像点击它一样?

2 个答案:

答案 0 :(得分:2)

试试这个:

$( "#foo" ).on( "click", function() {
  alert( $( this ).text() );
});

$( "#foo" ).trigger( "click" );

更多信息请参阅:jQueryDocumentation

答案 1 :(得分:1)



    $(document).ready(function(){
        $("p").click();
        alert("The paragraph was clicked.");
    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p> paragraphp will be click when the page loads </p>
&#13;
&#13;
&#13;