dojo 中使用 onclick 事件刷新页面,但我不想刷新页面

发布于 2024-09-24 15:52:16 字数 2595 浏览 2 评论 0原文

由于某些原因,在 IE8 中,当我在 onclick 事件后运行此函数时,它会导致页面刷新。我不希望发生页面刷新。

   var edealsButton = dojo.byId("edeals_button");
   var edealEmailInput = dojo.byId("edeals_email");
   var edealsSignup = dojo.byId("edeals_signup");
   var edealsThankYou = dojo.byId("edeals_thankyou");
   var currentValue = dojo.attr(edealEmailInput, 'value');
   if (currentValue != '' && currentValue != 'Enter your email') {
       var anim = dojox.fx.flip({
           node: edealsSignup,
           dir: "right",
           duration: 300
       })
       dojo.connect(anim, "onEnd", this, function() {
           edealsSignup.style.display = "none";
           edealsThankYou.style.display = "block";
       })
       dojo.connect(anim, "onBegin", this, function() {

           var criteria = { "emailAddress": '"' + currentValue + '"' };
           alert("currentValue " + currentValue);
           var d = essentials.CallWebserviceMethod('AlmondForms.asmx/SignupEdeal', criteria);
           d.addCallback(function(response) {
               var obj = dojo.fromJson(response);
               alert(obj.d);
               if (obj != null && obj.d != null) {
                   //alert(obj.d);
                   if (obj.d == false)
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       alert("edealError: " + edealError);
                       dojo.style(edealSuccess, "display", "none");
                       dojo.style(edealError, "display", "inline-block");
                   }
                   else
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       dojo.style(edealSuccess, "display","inline-block");
                       dojo.style(edealError, "display", "none");
                   }
               }
               else {
                   var edealSuccess = dojo.byId("edeals_succes_thankyou");
                   var edealError = dojo.byId("edeals_error_thankyou");

                   dojo.style(edealSuccess, "display", "none");
                   dojo.style(edealError, "display", "inline-block");
               }
           });
       })
       anim.play();
       edealEmailInput.innerHTML == 'Enter your email';
   } 
   else 
   {
       dojo.attr(edealEmailInput, 'value', 'Enter your email');
       dojo.style(edealEmailInput, 'color', '#CC2525');
   }

For some reason in IE8 when I run this function after an onclick event it causes a page refresh. I don't wan the page refresh to happen.

   var edealsButton = dojo.byId("edeals_button");
   var edealEmailInput = dojo.byId("edeals_email");
   var edealsSignup = dojo.byId("edeals_signup");
   var edealsThankYou = dojo.byId("edeals_thankyou");
   var currentValue = dojo.attr(edealEmailInput, 'value');
   if (currentValue != '' && currentValue != 'Enter your email') {
       var anim = dojox.fx.flip({
           node: edealsSignup,
           dir: "right",
           duration: 300
       })
       dojo.connect(anim, "onEnd", this, function() {
           edealsSignup.style.display = "none";
           edealsThankYou.style.display = "block";
       })
       dojo.connect(anim, "onBegin", this, function() {

           var criteria = { "emailAddress": '"' + currentValue + '"' };
           alert("currentValue " + currentValue);
           var d = essentials.CallWebserviceMethod('AlmondForms.asmx/SignupEdeal', criteria);
           d.addCallback(function(response) {
               var obj = dojo.fromJson(response);
               alert(obj.d);
               if (obj != null && obj.d != null) {
                   //alert(obj.d);
                   if (obj.d == false)
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       alert("edealError: " + edealError);
                       dojo.style(edealSuccess, "display", "none");
                       dojo.style(edealError, "display", "inline-block");
                   }
                   else
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       dojo.style(edealSuccess, "display","inline-block");
                       dojo.style(edealError, "display", "none");
                   }
               }
               else {
                   var edealSuccess = dojo.byId("edeals_succes_thankyou");
                   var edealError = dojo.byId("edeals_error_thankyou");

                   dojo.style(edealSuccess, "display", "none");
                   dojo.style(edealError, "display", "inline-block");
               }
           });
       })
       anim.play();
       edealEmailInput.innerHTML == 'Enter your email';
   } 
   else 
   {
       dojo.attr(edealEmailInput, 'value', 'Enter your email');
       dojo.style(edealEmailInput, 'color', '#CC2525');
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的奇迹 2024-10-01 15:52:16

看来您的“d.addCallback”代码可能无法正确处理。您可能想尝试将“dojo.stopEvent()”放在“anim.play();”之前行并查看这是否会停止回发。

api.dojotoolkit.org站点,dojo.stopEvent()“阻止传播并破坏传递事件的默认操作”。从 docs.dojocampus.org 站点,他们说“dojo.stopEvent(event) 将阻止两者的默认行为都是事件的任何传播(冒泡)。”

祝你好运,希望这对你有帮助。

It looks like your "d.addCallback" code might not be disposed of properly. You might want to try placing "dojo.stopEvent()" possibly before the "anim.play();" line and see if this would stop the postback.

From the api.dojotoolkit.org site, the dojo.stopEvent() "prevents propagation and clobbers the default action of the passed event". From the docs.dojocampus.org site, they say that "dojo.stopEvent(event) will prevent both default behavior any any propagation (bubbling) of an event."

Good luck, and hope this helps you out some.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文