开发者

jquery .trigger() doesn't seem to work

开发者 https://www.devze.com 2023-03-19 08:13 出处:网络
This is my code : $(document).ready(function () { //alert(\"wa\"); $(\"#wis\").trigger(\'click\'); $(\"#wis,#wib\").click(function (){

This is my code :

$(document).ready(function () {
//alert("wa");
$("#wis").trigger('click');
$("#wis,#wib").click(function (){
    alert("clciked");
    if(!$(this).hasClass("dealsb")) {

        $(".dealb").removeClass("dealsb");
        $(this).addClass("dealsb");
        var id=$(this).attr("id");
        $.post("deals.php",{'r开发者_开发知识库eq':id},function(data){
            //alert("works");
            $("#deals").html(data);});


        }

    }); 
});
</script>
<div id='wib' class='dealb'>What I've Purchased</div><div id='wis' class='dealb'>What I've Sold</div>
<div id="deals" style='position:absolute;left:0px;top:100px;width:600px;height:300px'></div>

Here $("#wis").trigger('click'); doesn't seem to work. When I click #wis or #wib though, the alert gets fired off and everything runs perfectly.


You're triggering it before you add the click handler, so the behavior you're seeing makes perfect sense. Move the trigger to the end of your <script> tag and you should be set.

0

精彩评论

暂无评论...
验证码 换一张
取 消