Override jQuery .val() function?

前端 未结 6 478
盖世英雄少女心
盖世英雄少女心 2020-12-01 10:41

Is there a way to easily override jQuery\'s val() function?

The reason I want to override it is that I want to add some processing each time a value is

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 11:05

    I know the problem is old but just to give a full solution. In order for both the jQuery.val() and the jQuery.val(value) to work after override you need to override it properly and separately. Because when calling jQuery.val() then originalVal.call(this, value); will not work correctly.

    To do it in a correct way you need to do something like that when getting the value: originalVal.call(this);

    Here is a site where everything is explained: http://extremedev.blogspot.com/2012/01/override-jqueryval-and-jqueryvalvalue.html

    Regards, Roman

提交回复
热议问题