开发者

Extending the Javascript prototype for all items of a certain class?

开发者 https://www.devze.com 2023-03-24 02:36 出处:网络
What is the best way to extend the Javascript prototype for all items of a certain class? I want all textboxes (input) of a certain class to have

What is the best way to extend the Javascript prototype for all items of a certain class? I want all textboxes (input) of a certain class to have

function OnValueChange()
{
// Wow!
}

This way I can add onblur="OnValueChange" to my input.

I can do it on an indiv开发者_运维问答idual object by modify the prototype, but I am wondering if there a way to it for all items of a certain class or other distinguishing attribute.

I have access to jquery in my project


If you have access to jQuery then just use :

$(".inputClassNameHere").live("blur", function(){OnValueChange();});

This way all current and future inputs with class inputClassNameHere will call OnValueChange when the blur event is triggered.

0

精彩评论

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