我正在尝试覆盖PrototypeJS中的Form.Element.disable()方法,以便它为禁用的表单元素添加自定义类。

我添加了:

Form.Element.disable = function(element) {
element = $(element);
element.blur();
element.disabled = true;
element.addClassName("disabled");
return element;}

加载prototype.js后的页面 - 如果直接调用,则可以正常工作,例如

Form.Element.disable("myInputBox");

但是如果我调用

,就会使用原始的PrototypeJS方法
$("myInputBox").disable();

我知道这与“范围”有关。我正在定义它 - 我正在有效地创建一个新的disable()方法实例,但我不知道如何移动范围,以便它取代原来的PrototypeJS版本。

我哪里错了?

有帮助吗?

解决方案

Form.Element.addMethods({
    disable: function(element) {
        // stuff here
    }
});

如果不起作用: http://api.prototypejs.org/ DOM /单元/ addMethods /

Element.addMethods(["input", "textarea", "select"], {
    disable: function(element) {
        // stuff here
    }
});

其他提示

Form.Element.prototype.disable = function(element) { ... }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top