html - 未调用原型(prototype)函数

标签 html prototypejs

是否有任何原因导致以下内容不起作用,它似乎适用于除以下情况之外的所有情况:

我的 html/asp.net

<div class="submitContainerConfirm" id="submit_Div">       
    <asp:PlaceHolder runat="server" id="phContinue">
        <asp:ImageButton CausesValidation="false" CssClass="ShowPleaseWait button" runat="server" ID="ibtnContinue" OnClick="ibtnContinue_OnClick" />
    </asp:PlaceHolder>
</div>

我的原型(prototype)

function pageLoad() {

$$(".ShowPleaseWait").each(function (el) {
    el.observe("click", function (event) {
        if (Page_IsValid) {
            el.hide();
            el.insert({ after: '<img src="/content/images/processing.gif" /> Please Wait...' });
            alert('Is Valid');
        }
        alert('Is not Valid');
    });
});

}

尝试二:

Event.observe(window, 'load', function () {

Event.observe("click", function (event) {
    if (Page_IsValid) {
        event.hide();
        event.insert({ after: '<img src="/content/images/processing.gif" /> Please Wait...' });
        alert('Is Valid');
    }
    alert('Is not Valid');
});

Event.observe("click", function (event) {
    if (Page_IsValid) {
        event.hide();
        event.insert({ after: '<img src="/content/images/processing.gif" /> Processing...' });
        alert('Is Valid');
    }
    alert('Is not Valid');
});

});

//这也不行。 请不要使用 jquery。

Example of asp rendered in html + prototypejs bizarrely not working.

最佳答案

在您的第二次尝试中,您没有为要监听的 observe 事件指定任何 element,它如何知道单击了哪个元素?

试试这个:

Event.observe(window, 'load', function() {
    $$('.ShowPleaseWait').each(function(el) {
        el.observe('click', function(ev) {
            if (Page_IsValid) {
                el.hide();
                el.insert({ 
                    after: '<img src="/content/images/processing.gif" /> Please Wait...'
                });

                alert('Is Valid');
            }

            alert('Is not Valid');
        });
    }); 
});

更新

参见 screenshot of generated page by JSFiddle , 这是 this 的直接输出 fiddle

关于html - 未调用原型(prototype)函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11143138/

相关文章:

javascript - 在原型(prototype)中获取图像的 alt 属性

javascript - 来自 prototype.js 的 bind() 代码

html - 为什么 flex 元素不缩小过去的内容大小?

jquery - 如何循环div的背景图?

html - Bootstrap .row margin-left : -15px - why is it outdented (from the docs)

JQuery 显示/隐藏其他更改

javascript - 链接到展示柜中图像的 ionic 复选框

javascript - 我如何从视频中检测字幕并将其复制到文本区域

Ajax 调用被浏览器取消

javascript - MooTools 和数组原型(prototype)