开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜