Jquery: Returning Value From Trigger

后端 未结 6 783
轮回少年
轮回少年 2021-02-02 10:14

I am using a trigger call a get a value from custom event but I want it to return a value and its only giving me Object Object when I do the following call:

var          


        
6条回答
  •  深忆病人
    2021-02-02 10:35

    Try this:

    $("#my_div").on("get_id", function(e, username){
        var user_id;
        if (username='fred'){
            user_id=1;
        }
        else if(username='mario'){
            user_id=2;
        }
        return user_id;
    });
    
    var user_id=$("#my_div").triggerHandler("get_id", ["username"]);
    

提交回复
热议问题