是否有任何原因导致以下内容不起作用,它似乎适用于除以下情况之外的所有情况:
我的 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/