Add jQuery function to specific elements

前端 未结 9 1464
悲&欢浪女
悲&欢浪女 2020-12-07 18:56

I know that you can add new jQuery functions by $.fn.someFunction = function()

However, I want to add functions to specific elements only. I tried this

相关标签:
9条回答
  • 2020-12-07 19:23

    I'm not also sure with my answer if this will help you but just a try how about using .live?

    $(selector).live(click,function(){
        //some codes here
    });
    
    0 讨论(0)
  • 2020-12-07 19:24

    Use .bind() and .trigger()

    $('button').bind('someFunction',function() {
        alert('go away!')
    });
    
    
    $('button').click(function(){
        $(this).trigger('someFunction');
    });
    

    As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document.

    0 讨论(0)
  • 2020-12-07 19:28

    I did this and its working fine..

     function do_write(){
         $("#script").append("<script> $(\'#t"+(id_app+4)+"\').change(function(){  alert('Write Your Code here');    });<\/script>");
         console.log("<script> $(\'#t"+(id_app+4)+"\').change(function(){  alert('hello');    });<\/script>");
    }
    

    and call function from your dynamic function which is creating a dynamic control in html

    0 讨论(0)
提交回复
热议问题