how to change onclick event with jquery?

后端 未结 7 1225
梦毁少年i
梦毁少年i 2020-12-08 09:01

I have create a js file in which i am creating the dynamic table and dynamically changing the click event for the calendar but onclicking the calender image for dynamic gene

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 09:41

    (2019) I used $('#'+id).removeAttr().off('click').on('click', function(){...});

    I tried $('#'+id).off().on(...), but it wouldn't work to reset the onClick attribute every time it was called to be reset.

    I use .on('click',function(){...}); to stay away from having to quote block all my javascript functions.

    The O.P. could now use:

    $(this).removeAttr('onclick').off('click').on('click', function(){ displayCalendar(document.prjectFrm[ia + 'dtSubDate'],'yyyy-mm-dd', this); });

    Where this came through for me is when my div was set with the onClick attribute set statically:

    Otherwise, if I only had a dynamically attached a listener to it, I would have used the $('#'+id).off().on('click', function(){...});.

    Without the off('click') my onClick listeners were being appended not replaced.

提交回复
热议问题